[Bug] 自定义 OpenAI-compatible 模型将 context window 误用为 max_tokens,导致 Ollama GLM-5.2 400
Nobody has claimed this yet.
- Dominant language
- No language data
- Stars
- 22
- Forks
- 1
- PR merge metrics
- No merged PRs in 30d
Description
提交前确认 · Pre-submission checklist
- 我已搜索过现有 issue,确认这不是重复 / I searched existing issues and confirmed this isn't a duplicate.
- 我已阅读 CONTRIBUTING.md / I've read CONTRIBUTING.md.
问题类别 · Category
模型设置 / 切换 · Model config
涉及的 Agent 框架 · Agent framework
ZCode Agent(自研)
严重程度 · Severity
阻塞使用 · Blocking
复现频率 · Reproducibility
必现 · Always
问题描述 · Description
在 ZCode Desktop 的 Model settings 中添加自定义 OpenAI chat completions (/v1/chat/completions) provider,接入本地 Ollama OpenAI-compatible endpoint 的 glm-5.2:cloud 时,如果按模型真实能力把 Context window 配成 200000 或 1000000,ZCode 会向 provider 发出过大的 max_tokens,导致请求被 Ollama 拒绝:
Provider rejected the model request.
Turn execution failed
Bad Request
provider=a9fb69dd-4c38-46b0-a9b4-74f10a9f3969 model=glm-5.2:cloud request=072b98c6-8e78-4d99-a6e4-d9fd03716c3f reason=invalid_request status=400 retryable=false
这看起来是模型设置里的 Context window 被用于输出上限 max_tokens 了。GLM-5.2 的上下文窗口约 976K/1M,但单次最大输出是 131072;二者不应共用同一个字段。
相关但不重复:#94 请求支持自定义 Payload。本 issue 更具体,指向现有模型设置字段到请求参数的映射 bug。
复现步骤 · Steps to reproduce
- 打开 ZCode Desktop → Settings → Model settings。
- Add provider:
- Name:
Ollama GLM - Base URL:
http://localhost:11434/v1 - API key:
ollama - API format:
OpenAI chat completions (/v1/chat/completions)
- Name:
- Add model:
- Model ID:
glm-5.2:cloud - Context window:
200000或1000000
- Model ID:
- 在 ZCode Agent 中选择该 custom provider/model,发送任意 prompt。
- 看到 provider 400 /
invalid_request。
期望表现 · Expected behavior
ZCode 应该区分:
{
"limit": {
"context": 1000000,
"output": 120000
}
}
或在 UI 中分别提供:
- Context window / input context limit:例如
1000000 - Max output tokens:例如
64000、120000,且不超过 provider/model 输出上限131072
请求 /v1/chat/completions 时,max_tokens 应来自 output limit,而不是 context window。
如果使用 /v1/responses,也应使用 max_output_tokens 表示输出上限;context window 仍不应直接映射到 max_output_tokens。
实际表现 · Actual behavior
当 model 的 Context window 设置为 200000 时,底层 OpenAI-compatible endpoint 返回:
max_tokens (200000) exceeds model's maximum output tokens (131072) for model glm-5.2
当设置为 1000000 时同理:
max_tokens (1000000) exceeds model's maximum output tokens (131072) for model glm-5.2
本地将 ZCode 配置手动改为同时包含 context 和 output 后可绕过:
"glm-5.2:cloud": {
"limit": {
"context": 1000000,
"output": 120000
},
"modalities": {
"input": ["text"],
"output": ["text"]
}
}
ZCode 版本 · ZCode version
- ZCode Desktop: log shows current app initialized as
3.1.3; updater downloaded3.2.5during the same run. - bundled ZCode CLI:
0.15.0
设备 / 系统 / 浏览器 · Device / OS / Browser
- macOS 26.3, Apple Silicon
- ZCode Desktop App
- Ollama OpenAI-compatible endpoint at
http://localhost:11434/v1
截图 / 录屏 / 日志 · Screenshots / Recordings / Logs
ZCode log excerpt:
{
"event": "model.request.failed",
"baseURL": "http://localhost:11434/v1",
"modelId": "glm-5.2:cloud",
"providerId": "a9fb69dd-4c38-46b0-a9b4-74f10a9f3969",
"providerKind": "openai-compatible",
"requestId": "072b98c6-8e78-4d99-a6e4-d9fd03716c3f",
"reason": "invalid_request",
"statusCode": 400,
"statusMessage": "Provider rejected the model request."
}
Local minimal reproduction against Ollama OpenAI-compatible endpoint:
POST http://localhost:11434/v1/chat/completions
model=glm-5.2:cloud
max_tokens=200000 -> 400
max_tokens=131072 -> 200
max_tokens=120000 -> 200
/v1/responses also works, but has the same output-token cap:
POST http://localhost:11434/v1/responses
model=glm-5.2:cloud
max_output_tokens=200000 -> 400
max_output_tokens=131072 -> 200
max_output_tokens=120000 -> 200
References:
- Ollama OpenAI compatibility docs: https://docs.ollama.com/api/openai-compatibility
/v1/chat/completionssupportsmax_tokens./v1/responsessupportsmax_output_tokens.- The OpenAI API does not have a way to set model context size directly.
- GLM-5.2 model page: https://ollama.com/library/glm-5.2
- lists
976K context window/ 1M long-context capability.
- lists
Suggested fix:
- Add a separate output-token field in custom model settings, or infer a safe output cap from model metadata.
- Store both
limit.contextandlimit.outputfor custom provider models. - For OpenAI-compatible chat completions, map only
limit.outputtomax_tokens. - For OpenAI Responses API, map only
limit.outputtomax_output_tokens. - Keep
limit.contextfor model/context budgeting and UI display, not as a request output limit.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the ZCode Desktop Model settings and the OpenAI-compatible /v1/chat/completions and /v1/responses request paths described in the report. Trace how custom model limits are stored and mapped; done means context and output limits remain distinct and requests use only the output limit for max_tokens or max_output_tokens, with the reported Ollama reproduction passing.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ollama
- Domain
- api, desktop
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100