Metric · LLM analytics

What is cost per 1M tokens, and how do you track it in Metabase?

Definition

Cost per 1M tokens is your effective, blended unit cost: total LLM spend divided by total tokens, normalized per million. Unlike a provider's published per-direction list price, it reflects your real mix of prompt and completion tokens, cache and batch discounts, and retries — which makes it the honest number for comparing models and catching cost drift.

Formula: 1,000,000 × SUM(cost_usd) ÷ SUM(prompt_tokens + completion_tokens), per model and per window

What data do you need?

  • Daily rollups per model with cost and token columns from the same source
  • Cache and batch discount fields where recorded, so the blended rate is explainable
  • Model metadata (list prices) if you want a drift-vs-list comparison column
  • Environment tags to keep test traffic out of the unit cost

SQL pattern

Blended cost per 1M tokens by model, trailing 30 daysPostgreSQL
SELECT
  model,
  SUM(requests) AS requests,
  SUM(prompt_tokens + completion_tokens) AS total_tokens,
  ROUND(SUM(cost_usd), 2) AS cost_usd,
  ROUND(
    1e6 * SUM(cost_usd)
    / NULLIF(SUM(prompt_tokens + completion_tokens), 0), 2
  ) AS cost_per_1m_tokens
FROM llm_request_rollups
WHERE window_start >= CURRENT_DATE - INTERVAL '30 days'
  AND environment = 'production'
GROUP BY model
ORDER BY cost_usd DESC;

Common pitfalls

Comparing your blended rate against a single list price.→ List prices are per direction (input vs. output). Your blended rate sits between them, weighted by your prompt:completion mix — compare it against a mix-weighted expected rate, not the headline price.
Computing unit cost across all models at once.→ A fleet-wide cost per token mostly measures model mix, not efficiency. Compute per model, and treat mix shifts as their own chart.
Letting test and playground traffic into the denominator.→ Dev traffic often skews small and cheap, flattering the rate. Scope to production and keep environment filterable.
Reading week-to-week noise as drift.→ Short windows are volatile when volume is low. Use trailing 30 days for the headline and alert on sustained movement, not single-week spikes.

Where does this metric apply?

This metric commonly uses data from Helicone request logs, OpenRouter activity exports, Langfuse cost rollups, Braintrust production logs, plus any warehouse models that provide the same grain of LLM usage data.

Dashboards

Integrations

Metrics

Analytics

FAQ

How do you calculate cost per 1M tokens?
Divide total spend by total tokens over the same window and multiply by one million: 1e6 * SUM(cost_usd) / SUM(prompt_tokens + completion_tokens), per model. Use the cost your gateway or tracing tool records at request time; it already reflects caching and batch discounts where the provider applies them.
Why did my cost per 1M tokens rise without a price change?
The usual suspects: the prompt:completion mix shifted toward the pricier direction, cache hit rate dropped, retries grew (paying twice for one answer), or reasoning-token share climbed. The metric is a smoke alarm — the diagnosis lives in the token-mix and cache charts next to it.
How do I use this metric to evaluate a cheaper model?
Compute the candidate's blended rate from a real traffic sample, not its list price — verbose models can erase a lower list price with longer completions. Then judge quality per dollar by pairing it with eval pass rate on the same dataset; the model usage & cost dashboard puts the two side by side.