Skip to main content

Module usage_accounting

Module usage_accounting 

Source
Expand description

Measured-cost plumbing: request-side opt-in (#1179) and response-header extraction (#1189).

OpenRouter only reports the billed charge (usage.cost, and cost_details.upstream_inference_cost for BYOK) when the request opts in with "usage": {"include": true}. This module decides when the proxy may inject that opt-in and performs the injection.

The gate is deliberately narrow: usage is not an OpenAI Chat Completions parameter — api.openai.com rejects unknown top-level fields with a 400, and other OpenAI-compatible upstreams (Azure, Groq, vLLM…) are not guaranteed to tolerate it either. Injection therefore only happens when the effective upstream host (post-routing) is openrouter.ai.

Gateways that report the bill out-of-band do it via response headers: LiteLLM sends x-litellm-response-cost (USD) on every proxied turn, and corporate gateways often expose an equivalent under their own name ([proxy] cost_response_header). cost_from_headers turns those into the same measured figure the OpenRouter body path produces.