Token usage counters for a single OpenAI Responses API call, nested inside Responses. Reports how many tokens were consumed by the prompt and by the generated output, used to track and cost AI feature usage. Any JSON fields OpenAI returns that are not otherwise mapped are captured in extraFields so they round-trip rather than being lost.
Properties
| Property | Returns | Description |
|---|---|---|
| extraFields | Map<String,Object> | Any usage fields OpenAI returned that are not mapped to a named property on this class. Kept so the response round-trips through serialisation without losing data as the OpenAI API evolves. |
| inputTokens | Integer | Number of tokens consumed by the input (prompt) sent to the model in this request. |
| inputTokensDetails | PromptTokenDetails | Breakdown of the input tokens, as reported by OpenAI for the input_tokens_details field, including how many were served from the prompt cache and so billed at the lower cached rate. |
| outputTokens | Integer | Number of tokens the model generated in its output for this request. |
| outputTokensDetails | CompletionTokenDetails | Breakdown of the output tokens, as reported by OpenAI for the output_tokens_details field. The reasoning tokens it reports are already counted within the output token total, so they are not costed again. |
| totalTokens | Integer | Total number of tokens consumed by this request, being the sum of the input and output token counts. |
Methods
getInputTokens()
Returns: Integer
Number of tokens consumed by the input (prompt) sent to the model in this request.
getOutputTokens()
Returns: Integer
Number of tokens the model generated in its output for this request.
getTotalTokens()
Returns: Integer
Total number of tokens consumed by this request, being the sum of the input and output token counts.
getInputTokensDetails()
Returns: PromptTokenDetails
Breakdown of the input tokens, as reported by OpenAI for the input_tokens_details field, including how many were served from the prompt cache and so billed at the lower cached rate.
getOutputTokensDetails()
Returns: CompletionTokenDetails
Breakdown of the output tokens, as reported by OpenAI for the output_tokens_details field. The reasoning tokens it reports are already counted within the output token total, so they are not costed again.
getExtraFields()
Returns: Map<String,Object>
Any usage fields OpenAI returned that are not mapped to a named property on this class. Kept so the response round-trips through serialisation without losing data as the OpenAI API evolves.