feat: support max_output_tokens in Responses API requests

Open 💬 1 comment Opened Jul 30, 2026 by inkOrCloud

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

  1. Use a Responses API proxy that defaults to 4096 max_output_tokens (e.g. DeepSeek upstream).
  2. Set reasoning_effort to xhigh.
  3. The model spends all 4096 tokens on reasoning and returns an empty or very short message output 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

  1. Add #[serde(skip_serializing_if = "Option::is_none")] pub max_output_tokens: Option<i64> to ResponsesApiRequest.
  2. Pass the value through from either ModelInfo or a config setting in build_responses_request().
  3. 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.

View original on GitHub ↗

1 Comment

wencai123 · 9 days ago

I also encountered this problem.