CyberRouter · Practical guides

Fix Context Too Large Errors in LLM and OpenCode Requests

Find which part of a request exceeds the endpoint’s limits, then make a deliberate change to history, tools, retrieval, or output.

By CyberRouter · Report a correction

Find the serving endpoint and its actual limits

A context-length error means the request does not fit one of the serving endpoint’s limits. The headline context window is only part of the check: providers can also impose separate input, output, or request-size caps. A gateway fallback may select an endpoint with a different limit.

Record the model ID, serving provider if known, requested output cap, and error code. Check the model’s endpoint details and provider documentation. Do not infer limits from a different model variant or from an AI client’s configuration alone.

A worked 32K request

This example assumes a shared 32,768-token window. The five-percent margin is a planning allowance, not a provider requirement. All counts below are illustrative.

An oversized request and one possible revision
AllocationBeforeAfter
Context window32,76832,768
System instructions2,0002,000
Conversation16,00010,000
Tools and retained results6,0006,000
Retrieved context6,0006,000
Output reserve4,0964,096
Margin (rounded up)1,6391,639
Remaining capacity−2,9673,033

Even without the planning margin, the original input plus output reserve exceeds the window by 1,328 tokens. Reducing retained conversation by 6,000 tokens makes this example fit. That change still needs a quality check: a summary that drops a requirement can make an answer worse.

Inspect the oversized budget or open the revised budget and replace the example counts.

Count the complete request

  1. Include system instructions, the current prompt, retained conversation, and message formatting.
  2. Count loaded tool definitions and retained tool results. An installed tool is not necessarily loaded on every request.
  3. Count the retrieved passages actually sent, including titles, citations, wrappers, and any security context added by the gateway.
  4. Reserve output, including reasoning tokens where the endpoint accounts for them that way. Check its separate output cap.

Use the endpoint’s tokenizer or supported counting API. The MCP schema calculator measures one normalized JSON encoding; it does not reconstruct every provider’s final request. The RAG guide explains passage overhead.

Adjust OpenCode deliberately

Check your installed OpenCode version and the configuration in the CyberRouter OpenCode setup guide. Set client context and output budgets within the selected endpoint’s limits, leaving room for gateway-added references. Increasing the configured limit does not expand the model’s capacity.

If the same configuration used to work, inspect growth in conversation, tool results, or retrieved content. Test a new short conversation with the same model and provider. A smaller successful request narrows the problem; it does not prove every longer request will fit. Consult OpenCode’s provider documentation for the installed configuration format.

Choose the smallest useful change

Remove duplicated passages, narrow retrieval, shorten repetitive tool descriptions, or summarize old conversation while retaining decisions and constraints. Lower the output reserve only if the task can finish within it. Change endpoints only after comparing capabilities, price, and access.

Retry the revised request once and inspect its usage. Repeating the identical oversized request or adding retries does not fix its capacity requirement. Authentication, credit, and rate-limit errors need different fixes; use the error reference to distinguish them.

Accessibility

Adjust how CyberRouter looks and moves. Preferences apply to this browser.

You can also use your browser’s zoom controls.

Accessibility help

Analytics preferences

Choose anonymous page counts or optional visit, scroll and reading-time analytics. Privacy details.