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

PropertyReturnsDescription
completionTokenDetailsCompletionTokenDetailsBreakdown of the completion tokens by reasoning, audio and predicted-output handling.
completionTokensIntegerNumber of tokens the model generated in its completion.
promptTokensIntegerNumber of tokens in the prompt sent to the model.
promptTokensDetailsPromptTokenDetailsBreakdown 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.
totalTokensIntegerCombined 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.

To get full access to the Kademi Hub existing customers can login here, or new customers can register here.