> ## Documentation Index
> Fetch the complete documentation index at: https://docs.muxx.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Cost Tracking

> Monitor and control your LLM spending with real-time cost tracking.

Muxx automatically calculates and tracks the cost of every LLM request, giving you complete visibility into your AI spending.

## How Costs Are Calculated

Costs are calculated based on:

1. **Model** - Each model has different pricing
2. **Input tokens** - Tokens in your prompt/messages
3. **Output tokens** - Tokens in the response
4. **Provider pricing** - Current rates from each provider

```
Cost = (Input Tokens × Input Price) + (Output Tokens × Output Price)
```

## Pricing Data

Muxx maintains up-to-date pricing for all supported models:

| Model             | Input (per 1M tokens) | Output (per 1M tokens) |
| ----------------- | --------------------- | ---------------------- |
| gpt-4o            | \$2.50                | \$10.00                |
| gpt-4o-mini       | \$0.15                | \$0.60                 |
| claude-3-5-sonnet | \$3.00                | \$15.00                |
| claude-3-5-haiku  | \$0.80                | \$4.00                 |
| gemini-1.5-pro    | \$1.25                | \$5.00                 |
| gemini-1.5-flash  | \$0.075               | \$0.30                 |

<Note>
  Pricing is updated regularly to reflect provider changes.
</Note>

## Viewing Costs

### Per-Request

Every request in the logs shows its cost:

* Input tokens and cost
* Output tokens and cost
* Total cost

### Dashboard Analytics

The dashboard provides cost analytics:

* **Daily/weekly/monthly spend** - Track spending over time
* **Cost by model** - See which models cost the most
* **Cost by user** - If using user metadata
* **Cost by feature** - If using feature metadata

## Spend Alerts

Set up alerts to avoid surprise bills:

1. Go to **Settings** → **Alerts**
2. Click **Add Alert**
3. Choose **Spend Alert**
4. Set threshold (e.g., \$100/day)
5. Select notification channel

## Spend Caps

Automatically stop requests when spending exceeds a limit:

1. Go to **Settings** → **Spend Caps**
2. Set a daily or monthly cap
3. Choose action: **Block** or **Alert Only**

When the cap is reached with **Block** enabled:

```json theme={null}
{
  "error": {
    "message": "Spend cap exceeded. Daily limit: $100.00, Current: $100.23",
    "type": "spend_cap_error"
  }
}
```

## Cost Optimization Tips

<AccordionGroup>
  <Accordion title="Use smaller models when possible">
    GPT-4o-mini is 20x cheaper than GPT-4o for many tasks.
  </Accordion>

  <Accordion title="Enable caching">
    Cached responses are free. Enable caching for repeated queries.
  </Accordion>

  <Accordion title="Optimize prompts">
    Shorter prompts = fewer input tokens = lower costs.
  </Accordion>

  <Accordion title="Set max_tokens">
    Limit output length to control output token costs.
  </Accordion>
</AccordionGroup>

## Exporting Cost Data

Export cost data for accounting:

1. Go to **Analytics** → **Costs**
2. Select date range
3. Click **Export CSV**

The export includes per-request costs, model breakdown, and totals.
