Tokens and usage
Token counters come in the usage object. The cost of a request is calculated from them, with the per-token prices from the model catalog. Occasionally usage does not arrive; see What to account for. The set of fields depends on the endpoint: the three chat formats count input differently, and embeddings and decisions have their own short usage.
Chat Completions
Section titled “Chat Completions”"usage": { "prompt_tokens": 68, "completion_tokens": 30, "total_tokens": 98, "prompt_tokens_details": { "cached_tokens": 0, "cache_write_tokens": 0, "audio_tokens": 0, "video_tokens": 0 }, "completion_tokens_details": { "reasoning_tokens": 0, "audio_tokens": 0, "image_tokens": 0 }}| Field | What it counts |
|---|---|
prompt_tokens | All input, including cached tokens |
completion_tokens | All output, including reasoning |
total_tokens | Input plus output |
prompt_tokens_details.cached_tokens | The part of the input read from the cache, billed at a lower rate |
prompt_tokens_details.cache_write_tokens | The part of the input written to the cache |
completion_tokens_details.reasoning_tokens | The part of the output spent on reasoning |
The nested fields are parts of the matching total, not additions to it. Uncached input is prompt_tokens - cached_tokens - cache_write_tokens.
Messages
Section titled “Messages”"usage": { "input_tokens": 65, "output_tokens": 137, "cache_read_input_tokens": 0, "cache_creation_input_tokens": 0, "cache_creation": { "ephemeral_5m_input_tokens": 0, "ephemeral_1h_input_tokens": 0 }}Messages follows the Anthropic convention: input_tokens is only the uncached input, and the cache comes in separate fields. To get the full input, add them up:
total input = input_tokens + cache_read_input_tokens + cache_creation_input_tokenscache_creation splits the cache write by lifetime (5 minutes and 1 hour), because they have different rates. See Prompt caching. Reasoning is included in output_tokens; see Reasoning.
Responses
Section titled “Responses”"usage": { "input_tokens": 14, "input_tokens_details": { "cached_tokens": 0 }, "output_tokens": 6, "output_tokens_details": { "reasoning_tokens": 0 }, "total_tokens": 20}Here input_tokens includes the cached part, as on Chat Completions, and cached_tokens shows how many of them were read from the cache. Reasoning tokens are in output_tokens_details.reasoning_tokens and are included in output_tokens.
Web search
Section titled “Web search”If the request turned on web search, usage on all three chat endpoints contains a server_tool_use block. The web_search_requests field counts the searches that ran:
"server_tool_use": { "web_search_requests": 1, "web_fetch_requests": 0 }Embeddings and decisions
Section titled “Embeddings and decisions”/v1/embeddings counts only input: its usage has prompt_tokens and total_tokens. /v1/systemone returns input_tokens and output_tokens. For details, see Embeddings and Decisions.
Streaming
Section titled “Streaming”With "stream": true, the counters arrive in the stream events, with no separate request needed:
/v1/chat/completions: the last chunk beforedata: [DONE]carriesusage;/v1/messages: saveusagefrommessage_startand update it with the fields frommessage_delta. Input and cache counts may appear only inmessage_start, and the final output count arrives inmessage_delta;/v1/responses: the final event (response.completedorresponse.incomplete) carries the finalusageinsideresponse.
If the client drops the connection midway, generation runs to the end and is billed in full. You cannot cancel a request by closing the connection.
Estimating cost
Section titled “Estimating cost”Per-token prices are in the pricing of each model in GET /v1/models and match your plan:
"pricing": { "prompt": "0.000002", "completion": "0.00001", "input_cache_read": "0.0000002", "input_cache_write": "0.0000025"}The cost of a request is a sum of products: uncached input times prompt, cache reads times input_cache_read, cache writes times input_cache_write, and output times completion. Some models have separate rates for reasoning (internal_reasoning), images, audio, and one-hour cache writes (input_cache_write_1h), and a fixed price per request (request). Reasoning, images, and audio with their own rate are subtracted from the output, so each token is billed once.
For some models, the price depends on the input size: above a certain number of input tokens, different rates apply. The catalog shows only the base rates, so for a long request, an estimate from the catalog may differ from the actual charge.
Searches run by the router are billed on top of tokens at their own price, which is not in the model catalog. See Web search.
The response has no cost field: calculate it from usage and the catalog, or see the actual charges in the console.
What to account for
Section titled “What to account for”- Tokens are not characters. On average, Russian text costs more than English text of the same length, because how text splits into tokens depends on the model.
- Attachments are tokens too. An image or a PDF turns into input tokens by the model’s rules. See Images and PDFs.
- Tools add to the input. The
toolsdefinitions are sent in every request of the loop and count as part of the prompt. - The cache changes how input is billed, not how much there is. The tokens do not go away; some of them are billed at the cache read price.
- Occasionally the
usageblock does not arrive at all. Tokens without counters are not billed, but the web searches that ran are charged and show up in the spending history.