Short answer
Count the tokens before you send, and keep each request inside the model’s context window, including the output you ask for. Send only the recent turns plus a short summary of older ones, split or retrieve parts of large documents instead of sending them whole, and lower the maximum output if it is set high. For long conversations on the Responses API, turn on compaction.
Why the request is too long, and the fix
01
The window counts input and output together
“This max tokens number includes input, output, and reasoning tokens.” OpenAI, Conversation state
The limit covers everything in the request: the system prompt, the history, any documents, and the output tokens you reserve. A request can fail even when the input alone looks small enough.
02
The chat history keeps growing
“Compaction helps you balance quality, cost, and latency as conversations grow.” OpenAI, Compaction
Apps that resend the whole conversation every turn hit the limit after enough messages. Keep the last few turns as they are and replace older ones with a summary, or drop them. Compaction, below, does this on the server.
03
Use compaction on the Responses API
“When the rendered token count crosses the configured threshold, the server runs server-side compaction.” OpenAI, Compaction
Set context_management with a compact_threshold on the request, and the server compacts the context when it grows past that size.
04
A whole document goes in every request
“You can estimate the number of tokens your messages will use with the tokenizer tool.” OpenAI, Conversation state
Count a file’s tokens before sending it. If it doesn’t fit, split it, or search it and send only the relevant parts.
Checked against the vendor’s docs on : OpenAI API docs: Conversation state (managing the context window); OpenAI API docs: Compaction; OpenAI API docs: Error codes.
Rather hand it over?
Fixed scope, fixed price, paid upfront. The work happens in writing; no call needed.
- $1,200API IntegrationTwo systems connected through their APIs, with retries, logs, failure alerts and tests.See scope and start
- from $450App Fix TicketOne reproducible bug in an existing mobile or web app, diagnosed and fixed.See scope and start
Related: OpenAI 429 insufficient_quota · OpenAI 401 Incorrect API key provided · Anthropic API 529 overloaded_error · Gemini API 429 RESOURCE_EXHAUSTED