Skip to content

openRouterCostUsd

function openRouterCostUsd(usage): number | undefined;

Defined in: core/src/providers/openai.ts:541

What an OpenRouter call cost, in USD, or undefined when it did not say.

Nothing has to ask for it. OpenRouter’s usage-accounting docs (read 2026-09-26) say every response now carries the full usage record, cost included, on the last frame of a stream, and that usage: { include: true } is deprecated and does nothing. Measured the same day: a streamed call and a plain one, neither sending the flag, both came back with usage.cost, the stream on its last frame. So the request does not send it.

With the caller’s own provider key (BYOK), cost is only OpenRouter’s fee. The inference is billed to the caller’s provider account and arrives as cost_details.upstream_inference_cost, so the call cost the two together. Without that second figure there is no whole bill to report, and the caller’s rate prices the call instead.

Exported for the other OpenRouter wire that bills the same way: Jev’s.

Parameter Type
usage { cost?: unknown; cost_details?: | { upstream_inference_cost?: unknown; } | null; is_byok?: boolean; }
usage.cost? unknown
usage.cost_details? | { upstream_inference_cost?: unknown; } | null
usage.is_byok? boolean

number | undefined