Set up
Wrap an instance ofOpenAI 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 ausage 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 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.