Overview
GoModel can return the cost it calculated for a request to the client that made it. It is off by default. Turn it on when clients account for their own spend per request — for example an application that holds an inference-only key and attributes cost to its own users — so they need neither an admin key nor a later lookup in/admin/usage/log.
The shape follows OpenRouter’s usage accounting: the cost is usage.cost, a JSON number in USD, in the usage object of the response. A client that already reads OpenRouter’s cost works against GoModel unchanged.
Estimating costs, pricing, markups and the dashboard totals are covered in Cost tracking.
Enable it
USAGE_ENABLED, on by default): a request without a usage row has no cost to return.
Read the cost
A buffered answer carries the cost in itsusage object and in two response headers:
Which cost
With markups enabled, the client gets the request’s billed cost, and GoModel removes every cost the provider reported in a field it reads costs from (see Upstream costs below), so the response reveals neither the provider cost nor the markup. A cost a provider reports in a field GoModel does not know is not recognised as one and stays in the response. With markups off, it gets the provider cost (total_cost), also for a provider marked billable: false. Either way it is in USD and an estimate like every cost GoModel calculates, and it is the value on the request’s usage row except for a cache hit without markups (see below).
Format. The amount is rounded to 12 decimal places and written as a plain decimal: no exponent, no float noise, no trailing zeros (0.00003, never 0.000030000000000000004; 0.000000001, never 1e-9).
Buffered responses
The cost is added at the end of the response’susage object:
Streamed responses
A stream sends its headers before the cost is known, so it carries the cost in its events only:usage.cost is added to the usage object of each event that carries usage, normally the one with the final token counts. Each event is relayed as soon as it is complete, when its blank line arrives; only the event still arriving is held.
Every other event passes through unchanged, unless it holds a cost field that is removed (see Upstream costs below). A provider that reports usage on several chunks gets
usage.cost on each of them that GoModel can price. The value is cumulative for the request so far, like the token counts in the same object: read it from the last event that carries usage, and never add them up. That value is the cost on the usage row. When the last usage event has no usage.cost, one on an earlier event covers the earlier token counts only (see Coverage and limits). A stream without usage carries no cost: GoModel asks providers for usage by default (ENFORCE_RETURNING_USAGE_DATA).
Unknown is not zero
A request’s cost is unknown when its model has no pricing and its provider reported no cost GoModel reads (OpenRouter, xAI and Eden AI report one, which prices a request even without model pricing). The response then carries nousage.cost and no header, in every mode. 0 always means a priced request that cost nothing.
Response-cache hits (
X-Cache: HIT) call no provider, so their provider cost is 0. Their usage row still records what the cached answer would have cost (total_cost), which is where the dashboard’s savings come from; that is not what the client spent. The cache stores answers without the cost, so a hit carries its own.
Upstream costs
An upstream may report its ownusage.cost: OpenRouter does, and so does another GoModel. With the setting on, usage.cost belongs to this gateway, and an upstream’s value is never presented as its own:
-
Every upstream
costmember is removed from every usage object GoModel reads, in any letter case, spelled with escapes, or repeated. The top-levelusageandresponse.usagethen end up with exactly onecost, this gateway’s, or none when that is unknown, so a parser that keeps the first or the last duplicate reads the same value.message.usageends up with none. -
GoModel reads three usage objects, in a buffered body and in a stream event alike: the top-level
usage,response.usageandmessage.usage. The cost is added tousageandresponse.usage;message.usage(Anthropic’smessage_start) only loses members. A usage object nested anywhere else is not edited. -
With markups enabled, every field GoModel knows a provider reports its cost in is removed too, all duplicates and case variants included, so a reseller’s customer learns neither the provider cost nor the markup:
These are exactly the fields GoModel reads a provider’s cost from for the usage log: both use one list, so a field GoModel learns to read is removed as well. With markups off they pass through exactly as received. GoModel never adds any of them.
- A cost field GoModel does not know cannot be removed. A provider that reports what a request cost under another name or in another place is relayed with it, with or without markups. Before reselling a provider that is not in the table, check what its responses contain.
-
Every
X-GoModel-CostandX-GoModel-Cost-Currencyheader from an upstream, in any letter case, is dropped; a buffered response then carries this gateway’s. -
A relayed JSON or SSE answer with a
Content-Encodingother thanidentityis refused with502. GoModel asks upstreams for no encoding and decodes gzip itself, so such an answer was sent unasked and cannot be read or cleaned. Other relayed content, such as audio, is not read, so it is relayed whatever its encoding.
usage.cost, cost_details and cost headers included.
Coverage and limits
What is buffered. To price it before it answers, GoModel reads a relayed JSON answer that is a single JSON object (
/p/{provider}/..., /v1/decisions, a natively forwarded /v1/messages) in full before it sends the first byte, instead of relaying it as it arrives. Nothing else is buffered:
- A relayed JSON answer that is not a single object, such as the JSON array Gemini’s
streamGenerateContentsends piece by piece withoutalt=sse, is relayed as it arrives and as it is. It is sent before it could be priced, so it carries no header and nousage.cost, and nothing inside it is edited: a cost member in such an array is not removed, with or without markups. No provider GoModel reads costs from answers this way. - In a JSON body only a usage object is held back while it is rewritten, from its opening to its closing brace, up to 64 MiB. (With markups, so are the bytes between two top-level members, up to 4 KiB, until the name of the second is read. A longer run of whitespace there is shortened to 4 KiB, which leaves the JSON unchanged; no cost member passes through because of it.) A larger usage object is relayed as it is: it gets no cost and keeps every member the upstream put in it.
- A stream is relayed event by event. An event ends at its blank line whether its lines end in LF, CRLF or a bare CR. Only streams framed with LF or CRLF, which is what providers send, are priced: from its first event that ends another way, a stream loses upstream costs but carries none. An event carries the cost of its own usage or none: when GoModel reads no usage from it, or its provider reported its own cost (OpenRouter, xAI, Eden AI) only for the token counts of an earlier event, it has no
usage.cost.
- A relayed JSON object over 8 MiB is unpriced: it carries no header and no
usage.cost, and an upstream’s costs are still removed. GoModel learns that it is too large only after reading the first 8 MiB, so those are sent together; the rest is relayed as it arrives. - A relayed answer is read only when its content type is JSON (
application/jsonor a+jsontype) ortext/event-stream. One sent as anything else, such as NDJSON or plain text, and a JSON body that starts with a byte order mark, is relayed as received: it carries no cost and keeps every cost field, with or without markups. - A stream event over 64 MiB is relayed unread, so it gets no cost and keeps whatever cost fields the upstream put in it. No provider sends usage in events that large.
- A stream event is cleaned only when its payload is well-formed JSON; one that does not parse is relayed as received.
- A JSON body is edited as it passes through and is not validated first, because that would mean holding all of it. A complete usage object is rewritten even when the body turns out to be malformed or cut off after it. A body cut off inside its usage object keeps that partial object as received; with markups, a root-level provider cost in front of it is already removed by then.
usage is its own), and MCP tool calls. Model calls the gateway makes itself while serving a request, such as an LLM guardrail, are recorded as their own usage rows and are not part of the returned cost. A workflow with usage tracking turned off returns none.