OpenCode: prompt is too long, and the field that decides when
A long OpenCode session stops answering and reports:
prompt is too long
That is the Anthropic wording. Point the same session at a different provider and the failure is the same but the string changes, which is why searching for it rarely finds an answer:
| Provider | What you actually see |
|---|---|
| Anthropic | prompt is too long |
| OpenAI | exceeds the context window |
| Google Gemini | input token count exceeds the maximum |
| DeepSeek / OpenRouter | maximum context length is X tokens |
| xAI (Grok) | maximum prompt length is X |
| GitHub Copilot | exceeds the limit of X |
| Groq | reduce the length of the messages |
| Amazon Bedrock | input is too long for requested model |
| llama.cpp | exceeds the available context size |
| LM Studio | greater than the context length |
| MiniMax | context window exceeds limit |
| Moonshot / Kimi | exceeded model token limit |
| Cerebras / Mistral | 400 (no body) or 413 (no body) |
| anything else | context length exceeded |
OpenCode recognises all of them as the same ContextOverflowError. The useful thing is not the string It is knowing which side decided the session was too long.
https://aicomp.ai/v1).
Create one free →
The field that decides when it happens
OpenCode does not wait for the provider to reject it. It compacts the session when it thinks the context is nearly full, and the number it uses comes from your config:
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"my-router": {
"npm": "@ai-sdk/openai-compatible",
"options": {
"baseURL": "https://aicomp.ai/v1",
"apiKey": "{env:MY_GATEWAY_KEY}"
},
"models": {
"claude-sonnet-5": {
"name": "claude-sonnet-5",
"limit": { "context": 200000, "output": 64000 }
}
}
}
}
}
limit.context is the number OpenCode compacts against. The failure mode is declaring a larger number than the endpoint actually accepts. If you declare 200000 and the model behind the endpoint takes 128000, OpenCode keeps sending because it believes there is room, and the provider rejects the request instead. You get the overflow error rather than an automatic compact.
So the first fix is not /compact — it is lowering limit.context to the smallest context in the set of models you might route to, so OpenCode summarises before the endpoint refuses. 200000 is the safe value in the docs only when the endpoint genuinely serves it.
limit.output matters for the same reason on the other end: an output ceiling above what the model will emit produces truncated work rather than an error.
What to do when it fires
/compact summarises the session in place and keeps working. /new starts clean. Both are documented as the fix, and both are after-the-fact, the session has already grown past the point where it was cheap to summarise.
The earlier lever is excluding files. An agent session accumulates every file it read and every command result it saw, and that accumulation is what crosses the line. If the session only needed four files and read forty, the forty are the problem, not the conversation.
Why this is also a cost problem
Context overflow and cost are the same mechanism seen from two ends. Every turn re-sends the accumulated context, so a session running near its ceiling is paying the largest possible input bill on every remaining turn — and a session that overflows near the end has paid for that context several times and produced nothing.
That is the argument for compacting early rather than late: summarising at 60% of the ceiling costs one summarisation and then holds input down for every turn after it, where waiting until 95% means the expensive turns have already happened.
It is also the argument for matching the model to the session. A long session on a model with a large window costs more per turn than the same session on one with a small window and aggressive compaction But the small-window model overflows sooner. The model price index is where the two curves are comparable, because input rate and window size are listed together.
Two neighbours that look similar
Concurrency limit exceeded for user is not context. It is parallel subagents exceeding the key's concurrency allowance, fewer subagents at once, or a higher concurrency limit.
ProviderModelNotFoundError is not context either. Model IDs are exact strings, addressed as providerID/modelID; dated snapshots and older names such as claude-3-5-sonnet-20241022 are not served. The model list refreshes after /models, not automatically.
Both show up in long sessions, which is why they get mistaken for overflow.
FAQ
FAQ
Why does the error say different things on different providers?
Because each provider phrases context overflow in its own words — Anthropic reports prompt is too long, OpenAI exceeds the context window, Gemini input token count exceeds the maximum, DeepSeek maximum context length is X tokens. OpenCode maps all of them to the same ContextOverflowError, so the fix is identical regardless of the wording.
What does `limit.context` in opencode.json actually do?
It tells OpenCode when to compact the session, before the provider rejects it. If you declare a larger number than the endpoint accepts, OpenCode never compacts and the request fails with an overflow error instead. Lower it to the smallest context among the models you route to.
Is `/compact` or `/new` the fix?
Both work, and both are after the fact The session has already grown past where summarising was cheap. The earlier lever is excluding files you did not need, and the real fix is a limit.context low enough that OpenCode compacts before the endpoint refuses.
Why do long sessions get expensive before they overflow?
Every turn re-sends the accumulated context, so a session near its ceiling pays the largest possible input cost on every remaining turn. Compacting at 60% of the ceiling costs one summarisation and holds input down after it; waiting until 95% means the expensive turns already happened.
Is `Concurrency limit exceeded for user` the same problem?
No. That is parallel subagents exceeding the key's concurrency allowance, not context size. Run fewer subagents at once, or ask for a higher concurrency limit.
Does the model list update automatically when I change config?
No. OpenCode refreshes the model list after the /models command, not automatically — a change to opencode.json will not appear in the picker until you run it.
Related
- OpenCode OpenAI-compatible provider —
opencode.json, base URL, and why/connectalone is not enough - Context limit cost — what a large window costs per turn
- Coding agent cost per month — how session shape drives the bill
- Cheapest models by workload, pick by shape, not list price
- How to calculate LLM cost — the method behind these numbers
- Model price index — input rates and context windows together