Usage Information
OpenRouter automatically returns detailed usage information with every response, including:- Input and output token counts using the model’s native tokenizer
- Cost in credits
- Reasoning token counts (if applicable)
- Cached token counts (if available)
response.completed or response.incomplete event for streaming responses, or in the terminal response for non-streaming requests. No additional parameters are required. The examples on this page use the Responses API.
Deprecated ParametersOn Chat Completions, the
usage: { include: true } and stream_options: { include_usage: true } parameters are deprecated and have no effect. The Responses API has no equivalent parameter. Full usage details are always included automatically in every response on both APIs.Response Format
Every response includes ausage object with detailed token information. The field names follow the API you call.
Responses API
Chat Completions
cached_tokens is the number of tokens that were read from the cache. cache_write_tokens is the number of tokens that were written to the cache (only returned for models with explicit caching and cache write pricing).
Cost Breakdown
The usage response includes detailed cost information:cost: The total amount charged to your accountcost_details.upstream_inference_cost: The actual cost charged by the upstream AI provider, split intoupstream_inference_input_costandupstream_inference_output_coston the Responses API (upstream_inference_prompt_costandupstream_inference_completions_coston Chat Completions)
Deferred-Tools Usage
When a request runs a managed multi-turn deferred-tools loop under theuniversal profile (see Tool Search), OpenRouter may execute more than one upstream model call before returning a single response. Usage is split so client context tracking stays accurate while billing reflects every turn (multi-turn runs under the portable profile instead report cumulative native token counts and omit deferred_tools_details):
- Native token fields report the final upstream model turn (
universalprofile).input_tokens/prompt_tokens,output_tokens/completion_tokens,total_tokens, and cache or reasoning token breakdowns (input_tokens_details,output_tokens_details,prompt_tokens_details,completion_tokens_details, and Anthropic’scache_read_input_tokens,cache_creation_input_tokens,output_tokens_details.thinking_tokens) reflect only the last upstream call. This lets agent harnesses such as Claude Code and Codex measure actual context-window fill without triggering premature compaction. costandcost_detailsreport the sum across all turns and billable router-run tools. The responsecost(and itscost_detailsbreakdown, includingserver_tool_costwhen used) totals every upstream model turn plus any billable router-run tools executed for that request.deferred_tools_detailsreports cumulative token totals across the run (universalprofile). Included on Chat Completions, Responses, and Anthropic Messages (streaming and non-streaming) foruniversalruns, and omitted onportableand standard requests. On Anthropic Messages streams, if a billable search turn completes and a later upstream turn fails, the stream can emit anerrorevent without a finalmessage_delta.usage; missing usage is not evidence that no work was billed. It uses the same field names across all three APIs:turns: Positive integer count of model turns with settled usage (failed upstream attempts that produced no settled usage are not counted).prompt_tokens: Prompt tokens summed across every settled model turn.completion_tokens: Completion tokens summed across every settled model turn.total_tokens: Sum ofprompt_tokensandcompletion_tokensacross every settled model turn.
input_tokens follows Anthropic’s convention of reporting uncached input tokens for the final turn (with cached reads in cache_read_input_tokens and writes in cache_creation_input_tokens), while deferred_tools_details.prompt_tokens sums total prompt tokens across every settled model turn.
Logs and Spend Thresholds
Each upstream model turn in a deferred-tools run is recorded and billed as its own generation row in Logs, linked to the parent request throughparent_generation_id (child turns carry spawned_by: "tool_search").
Spend added after the first model turn (later model turns, billed failed attempts, and any billable router-run tool costs) is gated by a pre-turn threshold of max($10, 6 × turn 1 cost) checked before starting another turn. Because the check runs before a turn starts rather than acting as a hard billing cap, a turn started while still under the threshold completes and is billed in full even if it crosses the threshold; no further turn is started afterward. If a run stops early at the spend threshold or turn limit, every upstream model turn that completed before the stop remains billed.
Benefits
- Efficiency: Get usage information without making separate API calls
- Accuracy: Token counts are calculated using the model’s native tokenizer
- Transparency: Track costs and cached token usage in real-time
- Detailed Breakdown: Separate counts for input, output, reasoning, and cached tokens
Best Practices
- Use the usage data to monitor token consumption and costs
- Consider tracking usage in development to optimize token usage before production
- Use the cached token information to optimize your application’s performance
Alternative: Getting Usage via Generation ID
You can also retrieve usage information asynchronously by using the generation ID returned from your API calls. This is particularly useful when you want to fetch usage statistics after the completion has finished or when you need to audit historical usage. To use this method:- Make your Responses API request as normal
- Note the
idfield in the response - Use that ID to fetch usage information via the
/generationendpoint
When obtaining usage information via generation ID, the
upstream_inference_cost field is only available for BYOK (Bring Your Own Key) requests. For all other requests it will be 0 or null.Examples
Basic Usage with Token Tracking
Output
Streaming with Usage Information
This example shows how to handle usage information in streaming mode:Output