usage object in their responses. This object provides details on the number of tokens used by the request, which is essential for tracking consumption and calculating costs.
Chat Completions
For non-streaming chat completions, theusage object includes the prompt tokens, completion tokens, and total tokens.
Example:
Streaming
For streaming requests, you need to setstream_options.include_usage to true to receive the usage information. With this option enabled, the usage object will be included in one of the last chunks of the stream, allowing you to account for usage and calculate costs.
Example:
Embeddings
The embeddings endpoint returns ausage object with prompt tokens and total tokens (since there are no completion tokens).
Example:
Images Generations
For images generations, theusage object may include input tokens (often null), output tokens, and total tokens.
Example: