Get input token counts
Returns input token counts of the request.
Returns an object with object set to response.input_tokens and an input_tokens count.
Parameters
A system (or developer) message inserted into the model’s context.
When used along with previous_response_id, the instructions from a previous response will not be carried over to the next response. This makes it simple to swap out system (or developer) messages in new responses.
Model ID used to generate the response, like gpt-4o or o3. OpenAI offers a wide range of models with different capabilities, performance characteristics, and price points. Refer to the model guide to browse and compare available models.
The unique ID of the previous response to the model. Use this to create multi-turn conversations. Learn more about conversation state. Cannot be used in conjunction with conversation.
Get input token counts
from openai import OpenAI
client = OpenAI()
response = client.responses.input_tokens.count(
model="gpt-5",
input="Tell me a joke."
)
print(response.input_tokens)
{
"object": "response.input_tokens",
"input_tokens": 11
}
Returns Examples
{
"object": "response.input_tokens",
"input_tokens": 11
}