context_length_exceeded is the code OpenAI returns in a 400 when a request does not fit the model's context window. It is a request problem, which means the identical body fails in the identical way each time you resend it; a plain retry loop will spin without ever getting through. The fix is to reduce what you send: trim or summarise the conversation history, ask for fewer output tokens, or choose a model with a larger window. Through https://api.uplinkswitch.com/v1, gpt-6.1-sol publishes its window in the catalog as context_window (1.1M), alongside its max_output_tokens cap, so a client can size a request before it sends one.
What it means, per OpenAI's docs
The OpenAI error-codes guide, when read on 2026-11-22, does not name context_length_exceeded. What it documents is the broader 400 BadRequestError family, whose rule is that the message tells you precisely what was invalid about the request. For this case the message names the window: the total of your input tokens and your requested output tokens is larger than the model can hold at once. The usual human-readable form of this, reported by developers and surfaced by the SDKs, reads along the lines of "this model's maximum context length is ... tokens" followed by how many your request asked for. Because the guide documents the family rather than this exact string, treat the precise wording as reported by users and the SDKs rather than as a line copied from OpenAI's published list.
The important mental model is that a context window is shared between what goes in and what you ask to come out. A prompt that fits comfortably on its own can still trip this error if you also request a large completion, because the two are summed against one ceiling. That is why the fix is sometimes "write less prompt" and sometimes "request less output."
What the gateway changes
These points are drawn from the gateway's published OpenAPI description. Because a 400 means the request itself is wrong, the gateway neither retries nor reroutes it: it goes to no other route and to no next id in a models list, since no destination would take the same oversized body. The response comes back in the OpenAI Error schema, with code, message, type and param, so a client that already handles OpenAI errors reads it unchanged, and the code is the field to branch on since the message text moves around. Every error also carries a request id in its headers, which is the reference to quote in a support thread.
Where the gateway genuinely helps is before the send. The catalog exposes each id's context_window and max_output_tokens, so a client can compute input plus intended output and compare it to the ceiling, turning a guaranteed 400 into a check it can make locally. A separate limit to keep distinct: the gateway rejects any body over 10 MB with a 413, which is a payload-size cap, not a token cap; a very large request can hit that first.
The anchor model here is gpt-6.1-sol, which read ok on the 2026-11-23 catalog and whose window appears above as 1.1M, with an output cap of 128K tokens.
How to fix it
- Measure first. Tokenise your input for the target model and add your requested output, then compare the sum against the catalog
context_window. This is the single check that prevents the error outright. - Trim or summarise the history. Keep only the turns the current step needs, or compress earlier context into a short brief that carries the same information in fewer tokens.
- Lower the requested output. If the input is large and you are also asking for a long completion, reduce the output budget so input plus output lands inside the window.
- Stream or chunk long sources. Process a long document in passes, or retrieve only the relevant passages, so no single request carries the whole thing.
- Move to a wider window only for bounded inputs. Read
context_windowfrom the catalog and choose an id with real headroom. Note that the current GPT, Claude and Gemini 3.8 windows published in the catalog sit close in size, so switching families is not a dependable escape from an overflow. - Rule out the 413. If the body is enormous rather than merely token-heavy, the 10 MB cap may be the real blocker; shrink the payload itself.
The Anthropic equivalent of this error is prompt is too long, the same overflow expressed in Anthropic's 400; if you run both providers behind one client, read the two together. For the concept beneath both, how a context window differs from an output cap, see context window vs max output tokens; that page owns the explanation and this one owns the error.