Implementation:Openai Openai python Input Token Count Params
| Knowledge Sources | |
|---|---|
| Domains | API_Types, Responses_API |
| Last Updated | 2026-02-15 00:00 GMT |
Overview
Concrete parameter type for counting input tokens before submitting a Responses API request, provided by the openai-python SDK.
Description
InputTokenCountParams is a TypedDict that mirrors the shape of a Responses API create request for the purpose of token counting. It includes all the major request fields such as conversation, input, instructions, model, reasoning, text, tools, tool_choice, truncation, and others. The type also defines helper type aliases Conversation (a union of str and ResponseConversationParam), Text (a TypedDict with format and verbosity), and ToolChoice (a union of multiple tool choice param types). This type is auto-generated from the OpenAI OpenAPI specification by Stainless.
Usage
Import InputTokenCountParams when you need to estimate input token counts for a planned Responses API request without actually executing it.
Code Reference
Source Location
- Repository: openai-python
- File: src/openai/types/responses/input_token_count_params.py
Signature
class InputTokenCountParams(TypedDict, total=False):
conversation: Optional[Conversation]
input: Union[str, Iterable[ResponseInputItemParam], None]
instructions: Optional[str]
model: Optional[str]
parallel_tool_calls: Optional[bool]
previous_response_id: Optional[str]
reasoning: Optional[Reasoning]
text: Optional[Text]
tool_choice: Optional[ToolChoice]
tools: Optional[Iterable[ToolParam]]
truncation: Literal["auto", "disabled"]
Import
from openai.types.responses import InputTokenCountParams
I/O Contract
Fields
| Name | Type | Required | Description |
|---|---|---|---|
| conversation | Optional[Union[str, ResponseConversationParam]] |
No | The conversation this response belongs to. Items from this conversation are prepended to input items. |
| input | Union[str, Iterable[ResponseInputItemParam], None] |
No | Text, image, or file inputs to the model. |
| instructions | Optional[str] |
No | A system (or developer) message inserted into the model context. |
| model | Optional[str] |
No | Model ID used to generate the response, like gpt-4o or o3.
|
| parallel_tool_calls | Optional[bool] |
No | Whether to allow the model to run tool calls in parallel. |
| previous_response_id | Optional[str] |
No | The unique ID of a previous response for multi-turn conversations. |
| reasoning | Optional[Reasoning] |
No | Configuration options for reasoning models (gpt-5 and o-series only). |
| text | Optional[Text] |
No | Configuration for text response format including format and verbosity. |
| tool_choice | Optional[ToolChoice] |
No | Controls which tool the model should use, if any. |
| tools | Optional[Iterable[ToolParam]] |
No | An array of tools the model may call while generating a response. |
| truncation | Literal["auto", "disabled"] |
No | The truncation strategy for the model response. |
Helper Types
| Name | Definition | Description |
|---|---|---|
| Conversation | Union[str, ResponseConversationParam] |
Conversation identifier or configuration. |
| Text | TypedDict with format and verbosity |
Configuration for text response format and verbosity level. |
| ToolChoice | Union of multiple ToolChoice*Param types |
Controls which tool the model should use. |
Usage Examples
from openai.types.responses import InputTokenCountParams
params: InputTokenCountParams = {
"model": "gpt-4o",
"input": "Explain quantum computing in simple terms.",
"truncation": "auto",
}
# Use with the input token count endpoint
token_count = client.responses.input_token_count(**params)
print(f"Estimated input tokens: {token_count}")