OpenAI context-size errors: input limits and output budgets

Diagnose separate input, output and combined context limits, count the complete request, and distinguish HTTP validation from failed agent turns.

By benchr Editorial Team · · · Changelog

Provider documentation read . Documentation review; no provider execution is established by this date.

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

  1. 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.
  2. Remove duplicate retrieval chunks and irrelevant history. Keep provenance so a shortened prompt still identifies its sources.
  3. Reduce the requested output allowance when the task can tolerate a shorter answer. Responses uses max_output_tokens; do not substitute a legacy max_tokens example without checking the endpoint.
  4. Use retrieval, task-specific summaries, or explicit context compaction when the workflow supports them. Check whether essential instructions or evidence were lost.
  5. 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.

Changelog

  • 2026-10-15 — Rebuilt context diagnosis around separate canonical input, output and combined caps, provider counting, truncation and agent-turn scope. Removed incomplete tokenizer arithmetic and universal max_tokens advice.
  • — Replaced the long-context recommendations (GPT-5.5, GPT-5.4, Claude Sonnet 4.6) with the current options: GPT-5.6 Terra, Luna, and Sol at 1.05M tokens, and Claude Sonnet 5 at 1M. The GPT-5 example is unchanged.
  • — Published. Status code, response shape, and the input-plus-reservation accounting verified against OpenAI's error-codes guide.

Sources and documentation review

Documentation review dates are recorded per source. No provider inference or independent benchmark replication was performed for this revision.

  1. GPT-5 exact input, context and output limits — read
  2. Context and conversation state — read
  3. Reasoning context accounting — read
  4. Responses input-token count reference — read
  5. Responses create reference — read
  6. Agents API error scope — read