You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
max_completion_tokens needs to be <= max_tokens - prompt_len #9611
With local models, opencode often reports errors like this one:
'max_tokens' or 'max_completion_tokens' is too large: 65536. This model's maximum context length is 65536 tokens and your request has 10969 input tokens (65536 > 65536 - 10969). (parameter=max_tokens, value=65536)
There SHOULDN'T be a problem here: the prompt is only 10k, and we have 64k available.
I believe this is happening because opencode is not actually respecting the model's max tokens in its requests to the llm -- in max_completion_tokens.
For example, if max_tokens is 10, and the prompt is 9, then max_completion_tokens should be no more than 1 (min(max_completion_tokens, max_tokens - prompt_len)).
Plugins
Just some skills
OpenCode version
1.1.26
Steps to reproduce
See session transcript. vllm; glm-4.7-flash, 64k context, launching with OPENCODE_EXPERIMENTAL_OUTPUT_TOKEN_MAX=65536 opencode.
Is this also related to the automatic context compression mechanism? Logically, when the condition "x > z−y" occurs, it indicates that OpenCode failed to perform compression in a timely manner. Claude Code has the same issue, which seems to be a problem with model support.
easy,
you should set max output tokenm in linux you can export OPENCODE_EXPERIMENTAL_OUTPUT_TOKEN_MAX=32000;
But there is another bug, only "finish-step" case (opencode/packages/opencode/src/session/processor.ts), it will compact context. If read tool return too many content, it also will trigger this error. I think this is a bug, need being fixed.
opencode web rebport: max_tokens=32000cannot be greater than max_model_len=max_total_tokens=28000. Please request fewer output tokens. (parameter=max_tokens, value=32000)
Activity
hsn8888866666-blip commentedon Jan 22, 2026
Is this also related to the automatic context compression mechanism? Logically, when the condition "x > z−y" occurs, it indicates that OpenCode failed to perform compression in a timely manner. Claude Code has the same issue, which seems to be a problem with model support.
hsn8888866666-blip commentedon Jan 22, 2026
like:
RNGMARTIN commentedon Feb 4, 2026
me too. Do you solve this problem?
khli-001 commentedon Feb 5, 2026
easy,
you should set max output tokenm in linux you can export OPENCODE_EXPERIMENTAL_OUTPUT_TOKEN_MAX=32000;
But there is another bug, only "finish-step" case (opencode/packages/opencode/src/session/processor.ts), it will compact context. If read tool return too many content, it also will trigger this error. I think this is a bug, need being fixed.
ZeusJupiter commentedon Mar 9, 2026
My config:
{
"$schema": "https://opencode.ai/config.json",
"disabled_providers": [],
"provider": {
"myprovider": {
"name": "MyProvider",
"npm": "@ai-sdk/openai-compatible",
"models": {
"glm-4.7-flash": {
"id": "glm-4.7-flash",
"name": "GLM-4.7-Flash",
"family": "glm-flash",
"attachment": false,
"reasoning": true,
"tool_call": true,
"temperature": true,
"knowledge": "2025-04",
"release_date": "2026-01-19",
"last_updated": "2026-01-19",
"modalities": { "input": ["text"], "output": ["text"] },
"open_weights": true,
"cost": { "input": 0, "output": 0, "cache_read": 0, "cache_write": 0 },
"limit": { "context": 200000, "output": 131072 }
}
},
"options": {
"baseURL": "http://127.0.0.1:8000/v1"
}
}
}
}
opencode web rebport: max_tokens=32000cannot be greater than max_model_len=max_total_tokens=28000. Please request fewer output tokens. (parameter=max_tokens, value=32000)
github-actions commentedon Jul 6, 2026
To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.