Repository navigation
fix(translator): emit max_completion_tokens for gpt-5/o-series in *-to-openai request builders - #3657
Open
AVK-Git-giddy wants to merge 1 commit into
Open
AVK-Git-giddy wants to merge 1 commit into
AVK-Git-giddy wants to merge 1 commit into
Conversation
…openai request builders
OpenAI's Chat Completions API rejects max_tokens for gpt-5.x and
hyphenated o-series models with 400 unsupported_parameter ("Use
'max_completion_tokens' instead"). The claude-to-openai,
gemini-to-openai and antigravity-to-openai request builders emitted
max_tokens unconditionally, so translated requests routed to the native
openai api-key provider failed at the provider for those models. The
GitHub executor already maps the param (requiresMaxCompletionTokens);
hoist the same match next to adjustMaxTokens and apply it in all three
builders so requests are born with the right param for every executor.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
luqman-v1
pushed a commit
to luqman-v1/9router-go
that referenced
this pull request
Sep 2, 2026
…#3657) Port decolua/9router#3657: OpenAI rejects max_tokens for gpt-5.x and o1/o3/o4 with 'Use max_completion_tokens instead'. Hoist matcher /gpt-5|o[134]-/i into requiresMaxCompletionTokens() and emit the correct param in TranslateClaudeToOpenAI. Add MaxCompletionTokens field to OpenAIRequest. Verified with gpt-5/o1-mini/gpt-4o tests.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
OpenAI's Chat Completions API rejects
max_tokensfor gpt-5.x and hyphenated o-series models:The claude→openai request builder emits
max_tokensunconditionally (open-sse/translator/request/claude-to-openai.js:22-24), and gemini→openai + antigravity→openai do the same. The GitHub executor already maps the param at its own layer (requiresMaxCompletionTokens,/gpt-5|o[134]-/i), but the nativeopenaiapi-key provider goes through the default executor, which never touches token params — so every Claude-format request (Claude Code, etc.) routed to anopenai/gpt-5.xmodel dies at the provider with the 400 above. We hit this in production routing Claude-format traffic to BYOK gpt-5 keys (observed live 2026-08-31).Fix
translator/formats/maxTokens.jsasrequiresMaxCompletionTokens, next toadjustMaxTokens.*-to-openairequest builders (claude-to-openai.js,gemini-to-openai.js,antigravity-to-openai.js), emit the adjusted budget asmax_completion_tokenswhen the model matches,max_tokensotherwise.Requests are born with the right param for every executor, and no downstream path regresses:
executors/github.jsmaps only whentransformed.max_tokens !== undefined→ clean no-op on the new field.translator/request/openai-responses.jsalready prefersmax_completion_tokenswhen mapping tomax_output_tokens.executors/opencode.jsnormalizes either field tomax_output_tokens;codex.js/grok-cli.jsdelete both;qoder.jsreads both.handlers/chatCore/requestDetail.jsOPTIONAL_PARAMSalready lists both; nothing inopen-sse/handlers/reads.max_tokenspost-translation.The GitHub executor's private copy of the regex is left untouched to keep the diff minimal — happy to point it at the shared helper here if you prefer.
Tests
New
tests/unit/to-openai-max-completion-tokens.test.js: the predicate plus each builder × (gpt-5.x, o3-mini, legacy gpt-4o) — 9/9 pass. The fulltests/suite has a byte-identical failure set with and without this change (the failures on a fresh clone of master are credential/environment-bound, none related).Related
max_tokensnot supported for newer OpenAI models (gpt-5.4-nano, gpt-5.4-mini, etc.) #1745, [Docker] Bug max_token vs max_completion_tokens with openai #2830, Bug: max_tokens is incompatible with openai/gpt-5.4-mini #3587.executors/default.js. That layer is still the right place to catch passthrough OpenAI-format ingress (deliberately not touched here); this PR fixes translated ingress at the source so it holds for every executor.reasoning_effortoutright (OpenAI's error directs to/v1/responses). The nativeopenaiprovider may want Responses-endpoint escalation the wayexecutors/github.jsalready does it (supportsResponsesEndpoint+ the openai-responses translators; cf. fix(openai): fallback to responses for gpt-5/codex #1797) — that would fix the whole class rather than one parameter name. Happy to open a separate issue with repro details if useful.🤖 Generated with Claude Code