Skip to main content

Set up

Wrap an instance of OpenAI from openai. The SDK recognizes it automatically, and both the Chat Completions and Responses APIs are covered.
The SDK never modifies your request. For streamed Chat Completions, set stream_options: { include_usage: true } yourself, or the provider sends no usage to meter.

What is reported

Every OpenAI response includes a usage object: the number of tokens the call consumed, split into input and output, with the number of input tokens served from OpenAI’s prompt cache. Prompt caching lets OpenAI reuse the start of a prompt from an earlier call at a lower price. The field names differ between the two APIs. The wrapper reads these counts and reports them to Stigg as the metrics below. For details on each field, see OpenAI’s Chat Completions reference, Responses reference and prompt caching guide. Chat Completions Responses
OpenAI includes cached tokens inside prompt_tokens and input_tokens. If you price both the input metric and cached_tokens, cached tokens are billed twice. Price one or the other, or use the normalized metrics. Likewise, total_tokens includes everything above: price the total, or the parts, but never both.
OpenAI has no field for cache creation, so a feature fed by cache_creation_input_tokens stays at zero for OpenAI traffic. Every usage field the vendor returns is also included, with a raw. prefix. See How usage is reported.