Billing basis
All amounts are in USD. The gateway counts in nano-USD (one billionth of a dollar) and never uses floating point for money, so a charge is exact: every line, the total and your balance add up to the nano-dollar.
What is charged
Section titled “What is charged”A request is priced from the counters of its usage. Each counter has its own price; a counter that is zero adds nothing.
Line (kind) |
Counter | Unit | When the model has no specific price |
|---|---|---|---|
input |
Input tokens that are not cached, image or audio | per million tokens | — |
output |
Output tokens that are not reasoning, image or audio | per million tokens | — |
reasoning |
Reasoning (thinking) tokens | per million tokens | the output price |
cache_read |
Input tokens served from the provider’s prompt cache | per million tokens | the input price |
cache_write_5m |
Input tokens written to a 5-minute prompt cache | per million tokens | the input price |
cache_write_1h |
Input tokens written to a 1-hour prompt cache | per million tokens | the 5-minute write price, then input |
image_input, audio_input |
Image or audio tokens in the input | per million tokens | the input price |
image_output, audio_output |
Image or audio tokens in the output | per million tokens | the output price |
input_chars |
Characters of text sent to a speech model | per million characters | — |
audio_input_seconds |
Seconds of audio sent to a transcription model, counted in milliseconds | per second | — |
images |
Images generated, optionally priced by <quality>:<size> |
per image | — |
web_search |
Web searches the model ran | per search | — |
request |
The request itself | per request | — |
The counters are disjoint. A cached token is billed once, at the cache-read price, and is not also counted as an input token; a reasoning token is billed as reasoning and is not also an output token. The usage object in a response follows the dialect you called (OpenAI’s prompt_tokens includes cached tokens, Anthropic’s input_tokens does not), so to see exactly what was billed read usage and cost_details in /v1/generation, which always use the disjoint counters.
Context tiers
Section titled “Context tiers”A model can have several price tiers keyed on the size of the prompt. The tier is chosen once per request from the number of context tokens (all input-side tokens: plain, cached, cache-written, image and audio input), and its prices apply to the whole request, not only to the tokens above the threshold.
Provider prices and discounts
Section titled “Provider prices and discounts”The model’s sell price is the default. An operator can set a different price for one provider of a model; the price used is that of the provider that served the request (routing). The price is pinned when the request starts: a price change affects later requests only.
An organisation can have a discount, in parts per million of the list price. It is applied once, to the sum of all lines.
Rounding
Section titled “Rounding”The sum of all lines is computed exactly at list price, the discount is applied, and the result is rounded up to a whole nano-USD once, for the whole request. The amount of each line in cost_details is its share of that total; the shares add up to the total exactly.
Illustration with made-up prices of 0.15 USD per million input tokens and 0.60 USD per million output tokens, 1,200 input tokens and 300 output tokens, no discount:
input 1,200 × 0.15 / 1,000,000 = 0.00018 USDoutput 300 × 0.60 / 1,000,000 = 0.00018 USDtotal 0.00036 USD (360,000 nano-USD)When nothing is charged
Section titled “When nothing is charged”| Situation | Charge |
|---|---|
| The request is refused before any provider is called (bad key, bad body, rate limit, balance) | none |
Every provider failed, or the provider rejected the request itself (client_error, upstream_error) |
none |
| Some attempts failed and a later one succeeded | the successful attempt only |
The response was delivered completely (success) |
full price |
The stream broke or was cut after content was delivered (partial) |
what was delivered |
You disconnected after the provider started answering (canceled) |
see Streaming |
Failed attempts cost you nothing; what they cost the gateway is not passed on.
When the provider reports no usage
Section titled “When the provider reports no usage”Some providers and some streaming paths report no token counts, or only provisional ones. The gateway then counts the delivered text with its own tokenizer estimate and bills that. Such a record has usage_estimated: true in /v1/generation and usage.source: "estimated". The estimate is deterministic, is meant to be close rather than exact, and never undercuts what was actually delivered. Where the provider’s own count is final, the provider’s count is used as is.
What is held while a request runs
Section titled “What is held while a request runs”Before a request goes to a provider, the gateway holds the worst-case cost of it on your balance: the estimated input tokens plus the output ceiling, priced at the model’s current price with your discount. The ceiling is the max_tokens you send, else the model’s maximum output, else a deployment default. When the request ends, the hold is replaced by the real charge and the rest is free again. A long stream keeps its hold alive and extends it if the cost approaches it.
Consequences:
- A request is refused with
402 insufficient_balancewhen your spendable balance, minus the holds of requests already running, is below the worst case of this request, even if its real cost would have been small. A largemax_tokenson a small balance is the usual cause. Send themax_tokensyou need. - Holds of concurrent requests add up. Running 20 requests with large ceilings at once needs 20 holds.
- The same worst-case amount is checked against the key’s spend limit (
402 key_spend_limit_exceeded) and the organisation’s daily cap (402 daily_spend_cap_exceeded). - If the balance cannot cover a stream as it grows, the stream is ended and billed for what was delivered (Streaming).
- When a hold cannot be created because the gateway’s billing store is unavailable, the request is refused (
503 billing_unavailable); it is never served unbilled.
Keep the balance up with auto recharge and a low balance alert.