Skip to content

Cost Control ​

Cost control in LLM Proxy relies on model pricing, key and account budgets, and usage tracking.

1. Prices ​

Cost is calculated from the pricing fields on each model record, or from a provider mapping when overridden there. See Models & Pricing for field names, units, and tiers.

To populate prices for existing models:

  1. Open Models → Sync from models.dev and review the pricing diff preview (nothing is written yet).
  2. Confirm to write mapping-level pricing. Unchecked rows keep their manual values.
  3. Fill in any models not covered by the catalog manually.

cost_usd: null is not $0

A null cost means the cost is unknown, either because no rate is configured or because the request had nothing billable. Budget checks only count spend when a rate exists to compute it, so configure prices for every model you serve.

Pricing can also vary by context tiers (above an input token threshold), time windows (peak/off-peak, evaluated in the window's own timezone), and service tiers (flex or priority, selected by the request's service_tier). They apply in that order, each overriding only the rates it defines. On a provider mapping, leaving an overlay null inherits the model-level setting, while an explicit empty list or map disables it for that upstream. Reasoning tokens are billed at reasoning_cost_per_1m when set, and at the output rate otherwise.

openrouter and nanogpt report their own cost per request. Their reported figures replace the computed cost, including any upstream peak/off-peak or service-tier discounts.

2. Budgets ​

Budgets are checked on every billable request carrying an API key. Read endpoints (GET and HEAD under /v1/*, such as model lists, stored responses, files, and batch listings) still authenticate and apply rate limits, but are never blocked by budget so clients can still inspect available models when a key is exhausted.

BudgetScopeSet inReset
Key budgetOne API keyAPI KeysOwner via Reset (POST /api/api-keys/{name}/budget/reset)
Account budgetAll of a user's keys combinedUsers & RolesAdmin only (POST /api/team/members/{user_id}/budget/reset)
  • Periods: daily (00:00 UTC), weekly (ISO Monday), monthly (configurable reset day, default the 1st), or lifetime (since the last reset).
  • Over-budget responses return 429 budget_exceeded (or user_budget_exceeded for account budgets). If spend cannot be read, the check fails closed and rejects the request.
  • Enforcement always uses the UTC calendar window. The range selector in the usage panel is for inspection only.

Typical production setup:

KeyBudgetPurpose
prod-backendMonthlyCaps service spend, aligned with your billing cycle
dev-playgroundDaily (small)Catches runaway loops early
one-off-batchLifetimeEnforces a fixed project cap

Pair budgets with rate_limit_rpm so a traffic burst cannot exhaust a budget in seconds.

3. Visibility ​

SurfaceShows
Usage dashboardSpend, tokens, requests, success rate, cache savings, trends, per-provider and per-model breakdowns
Logs → Proxy LogsPer-request cost, tokens, cache tokens, retries, and fallbacks
GET /api/logs/usage-statsAggregated usage as JSON, filtered by date range
GET /api/api-keys/spend/summaryCurrent spend per key
GET /api/api-keys/{name}/usageOne key's usage over a date range
GET /api/me/budgetYour account budget status

Cache savings require cached_read_cost_per_1m on the model; without it, the metric is skipped and a warning is logged. The figure is net: cache-write premiums are subtracted from read savings, so a turn that writes a prefix once and reads it once reports a net cost. Set cached_write_long_cost_per_1m when an upstream charges more for long-lived cache writes (such as OpenAI's 12-hour writes), or those tokens bill at the standard cache-write rate.

4. Reduce spend structurally ​

  • Use smart routing (fast, auto, best) to send simpler requests to cheaper models. Log metadata records routing_savings per request, and weak/strong feedback tunes routing over time. See Virtual Models & Routing.
  • Set provider selection to cost_optimized to order equal-priority providers by price, or balanced to weigh price against observed latency.
  • Configure cache read and write rates so cache hits are billed accurately and savings are tracked.
  • Use model allowlists to restrict keys to the cheaper models they need.

Example: audit yesterday's spend ​

bash
curl -s "http://localhost:8080/api/logs/usage-stats?start_date=2026-09-12&end_date=2026-09-12" \
  -H "Authorization: Bearer $ADMIN_JWT" | jq '{
    cost: .summary.total_cost,
    requests: .summary.total_requests,
    success_rate: .summary.success_rate,
    cache_savings: .summary.cache_savings_usd,
    top_models: (.by_model | sort_by(-.cost) | .[:5])
  }'

MIT licensed