POST/responses/input_tokens

Get input token counts

Counts the input tokens for a response request. Provide the model and any input or conversation context to count, and use input_tokens in the result to inspect the count. Do not combine previous_response_id with conversation.

  • IdempotentThe SDK sends Idempotency-Key, so a retried request is only applied once.

12 body fields

Optional response request data for counting input tokens; all fields are optional.

modelstringoptional
The model ID to use, such as `gpt-4o` or `o3`.
inputstring | arrayoptional
Text, image, or file input to include in the token count.
previous_response_idstringoptional
The unique ID of a previous response to use for conversation context. Do not use together with `conversation`.
toolsarray<Function>optional
Tools the model may call while generating a response.
textobjectoptional
Configuration options for a plain-text or structured JSON response.
reasoningobjectoptional
Configuration options for reasoning models.
truncationstringdeprecatedoptional
The truncation strategy to use for the model response. - `auto`: If the input to this Response exceeds the model's context window size, the model will truncate the response to fit the context window by dropping items from the beginning of the conversation. - `disabled` (default): If the input size will exceed the context window size for a model, the request will fail with a 400 error.
Allowed:autodisabled
instructionsstringoptional
A system or developer message to include in the model's context.
personalitystringoptional
A model-owned style preset to apply to this request. Omit this parameter to use the model's default style. Supported values may expand over time. Values must be at most 64 characters.
conversationstring | objectoptional
The conversation to include as context, specified by its identifier or an object. Do not use together with `previous_response_id`.
Default:null
tool_choicestring | objectoptional
How the model selects which tool or tools to use.
parallel_tool_callsbooleanoptional
Whether to allow the model to run tool calls in parallel.

3 status codes
200Returns an object identifying the result as `response.input_tokens` and containing the input token count.
objectstringrequired
Allowed:response.input_tokensDefault:response.input_tokens
input_tokensintegerrequired
400Returned when the token-count request is invalid or contains incompatible parameters.
errorobjectrequired
429Returned when the request exceeds a rate limit.
errorobjectrequired

Error handling

A 400 is returned when the request is invalid or contains incompatible parameters, including using previous_response_id with conversation. A 429 is returned when the request exceeds a rate limit.