A context-size failure is not repaired by resending the same oversized request. Determine the selected model's maximum input, combined context window, and maximum output separately, then inspect everything the endpoint places in context. A count of the latest user message is not the size of a conversation.
Three limits, not one headline number
For the documented GPT-5 deployment, the combined window is 400,000 tokens, maximum input is 272,000 tokens, and maximum output is 128,000 tokens. A prompt below the headline window can still exceed the input allowance. Lowering output alone cannot make an input above that separate cap valid.
For a model with these three documented caps, check input ≤ maximum input, requested output ≤ maximum output, and input + reserved output ≤ combined context. Preserve any endpoint-specific requirements on top of that arithmetic. Reasoning can consume the output allowance; it is not an extra pool of free context. Other deployments can have different limits, so use the exact model's context record.
Count the request the provider will receive
Include system and developer instructions, retained conversation items, retrieved passages, tool definitions and outputs, attachments, and modality-specific representation. A local tokenizer over concatenated message text omits structure and non-text inputs. Treat a local estimate as a preflight aid with headroom, not an authoritative accounting of every endpoint.
OpenAI documents POST /v1/responses/input_tokens for counting Responses input. Supply the selected model and the same supported input, instructions, conversation state, and tool configuration that matter to the request. The endpoint returns an input_tokens count. Its schema does not make the inference output allowance disappear; compare that count with the model's input and combined limits before reserving output.
This endpoint was reviewed in the official API reference but was not called with credentials for this guide. The local token counter also states its estimation boundary. Neither a character count nor a successful metadata request establishes that a long prompt fits.
Choose what to remove deliberately
- Measure the assembled request, then identify the largest component. Repeated tool outputs and retained assistant turns are common things to inspect, not an assumed diagnosis.
- Remove duplicate retrieval chunks and irrelevant history. Keep provenance so a shortened prompt still identifies its sources.
- Reduce the requested output allowance when the task can tolerate a shorter answer. Responses uses
max_output_tokens; do not substitute a legacymax_tokensexample without checking the endpoint. - Use retrieval, task-specific summaries, or explicit context compaction when the workflow supports them. Check whether essential instructions or evidence were lost.
- Consider a different model only after comparing its documented input/output limits, required modalities, price conditions, and task results. A larger advertised window is not a measured retrieval-quality guarantee.
Automatic truncation can change the task
The current Responses reference marks truncation deprecated while still documenting "disabled" as its default: an input beyond the context window fails with HTTP 400. With "auto", the documented behavior drops items from the beginning of the conversation to fit. That can remove facts or constraints the application expected to preserve. For a new integration, review current context-management and compaction guidance rather than assuming a deprecated field is the preferred long-term control.
Do not assume one universal error envelope across OpenAI interfaces. The Agents API separately documents context_length_exceeded as a failed-turn code after work starts. That is distinct from a request-level HTTP validation error. Inspect the actual HTTP response or saved turn error for the endpoint you use.
Make the boundary a regression case
Keep test cases just below, at, and above the documented input, output, and combined limits. Test the assembled request builder with long tool results and retained history, not only a string tokenizer. The shared benchr pricing engine tests separate input and combined caps using canonical records; this validates local quote admission, not OpenAI's server implementation.
For a recurring failure, log the model ID, endpoint, estimated or provider-counted input, requested output allowance, structured code, and request ID. Keep sensitive document content out of routine logs. A useful error tells the user what needs to shrink and preserves their unsent work.