Token usage OpenAI reports for a chat completion request, covering the prompt and completion token counts and their combined total. Nested inside ChatCompletionResponse as the usage field, and read by the LLM providers to record how many tokens a request consumed.
Properties
| Property | Returns | Description |
|---|---|---|
| completionTokenDetails | CompletionTokenDetails | Breakdown of the completion tokens by reasoning, audio and predicted-output handling. |
| completionTokens | Integer | Number of tokens the model generated in its completion. |
| promptTokens | Integer | Number of tokens in the prompt sent to the model. |
| promptTokensDetails | PromptTokenDetails | Breakdown of the prompt tokens, as reported by OpenAI for the prompt_tokens_details field, including how many were served from the prompt cache and so billed at the lower cached rate. |
| totalTokens | Integer | Combined prompt and completion token count for the request. |
Methods
getPromptTokens()
Returns: Integer
Number of tokens in the prompt sent to the model.
getCompletionTokens()
Returns: Integer
Number of tokens the model generated in its completion.
getTotalTokens()
Returns: Integer
Combined prompt and completion token count for the request.
getCompletionTokenDetails()
Returns: CompletionTokenDetails
Breakdown of the completion tokens by reasoning, audio and predicted-output handling.
getPromptTokensDetails()
Returns: PromptTokenDetails
Breakdown of the prompt tokens, as reported by OpenAI for the prompt_tokens_details field, including how many were served from the prompt cache and so billed at the lower cached rate.