LLM ROUTING

OpenRouter usage: reconciling tokens and request cost

In this article
THE QUICK TAKE

Account for executions rather than displayed text; one application task may create several separately billable attempts.

Build OpenRouter usage accounting around an execution and its identifier, rather than the length of text displayed to the user. Input, output, caching and additional features can follow different accounting rules. Reconciliation needs actual execution data and explicit cost units, especially when one application task creates several attempts.

Preserve execution identity

Associate the returned generation identifier with your internal task ID, time and requested model. OpenRouter provides a documented operation for generation metadata. Keep the safe fields needed to investigate an execution without retaining the entire private document or exposing a credential.

A retry should not overwrite the original execution record. If a task has three attempts, preserve three observations linked to the task. This allows the team to explain partial answers, interrupted streams and additional usage instead of attributing every charge to the final visible answer.

Separate the accounting dimensions

Record fieldPurpose
Requested and actual modelUnderstand routing outcomes
Finish stateSeparate completion, failure and cancellation
API-reported tokensMeasure the observed execution
Cost and unitReconcile the charge with its rate
Credential route, where availableDistinguish BYOK from shared capacity

Do not infer token count from characters or a word-processing application’s page total. Use the API’s actual measurements and retain their meaning. Different fields can describe different parts of an operation; they should not be added together simply because each contains a number.

Check streaming completion separately

HTTP headers or the first text event do not establish that usage and completion data have arrived. Test a normal stream, an interrupted stream and a deliberate cancellation. Record missing accounting information as unknown until a supported metadata route or later record resolves it.

The application should distinguish a complete answer from partial output while preserving the task’s attempts. A failed visible result does not necessarily mean no upstream work occurred. Avoid automatic retries that erase the evidence needed to understand those cases.

Reconcile the full billing period

Pricing distinguishes model-token charges from platform conditions. BYOK also needs the upstream provider’s invoice, and enabled services may have separate components. Keep the units and applicable plan date with the calculation instead of using one rate as an estimate for the entire pipeline.

At period end, compare the execution ledger with the relevant account records. Explain unmatched operations before scaling up. For GPU and operations funding, use representative measured workloads and explicit assumptions.

Official references: openrouter.ai — get request & usage metadata for a generation, openrouter.ai — pricing.

Related guides: OpenRouter BYOK pricing: separating the parts of the bill, OpenRouter prompt caching: verifying savings in usage data.

← All articles