feat: support max_output_tokens in Responses API requests
Summary
Codex currently does not set max_output_tokens when constructing Responses API requests via ResponsesApiRequest. This means API proxies that have a lower default max_output_tokens (e.g. 4096) will silently truncate model output — a problem that is especially severe when combined with high reasoning_effort, because reasoning consumes tokens from the same budget and can leave almost nothing for the actual message text.
Root cause
Three code locations are missing max_output_tokens support:
1. ResponsesApiRequest — the wire-format struct
File: codex-rs/codex-api/src/common.rs
The struct serialized into the API request body has no max_output_tokens field, so it is never sent to the API server.
2. ModelInfo — model-catalog metadata
File: codex-rs/protocol/src/openai_models.rs
No max_output_tokens field exists per-model, so different models cannot advertise their output limits.
3. Config — user configuration
No max_output_tokens configuration option exists in config.toml for the user to override the default.
How to reproduce
- Use a Responses API proxy that defaults to 4096
max_output_tokens(e.g. DeepSeek upstream). - Set
reasoning_efforttoxhigh. - The model spends all 4096 tokens on reasoning and returns an empty or very short
messageoutput item.
Verified by direct API testing:
| Test | Parameter | output_tokens | Result |
|---|---|---|---|
| No override | — | 4,096 | ❌ Hard-cut |
| max_tokens: 8192 (Chat API field) | 4,096 | ❌ Ignored |
| max_output_tokens: 8192 (Responses API field) | 8,192 | ✅ Works |
Suggested changes
- Add
#[serde(skip_serializing_if = "Option::is_none")] pub max_output_tokens: Option<i64>toResponsesApiRequest. - Pass the value through from either
ModelInfoor a config setting inbuild_responses_request(). - Optionally expose it as a per-model field in the catalog so proxies can advertise their actual limit.
Workaround
Users currently have no way to configure this. The only workaround is to lower reasoning_effort or fix the API proxy upstream.
1 Comment
I also encountered this problem.