fix(openai): omit stop parameter for o-series and gpt-5+ models#12592
Open
rodboev wants to merge 1 commit into
Open
fix(openai): omit stop parameter for o-series and gpt-5+ models#12592rodboev wants to merge 1 commit into
rodboev wants to merge 1 commit into
Conversation
febe921 to
c854a3e
Compare
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.
Fixes #8184
Summary
GPT-5-nano, gpt-5-mini, o1, o1-mini, o3, o3-mini, and related models return HTTP 400
"Unsupported parameter: 'stop' is not supported with this model."for every chat and autocompleterequest. The autocomplete template always supplies stop tokens, and
getMaxStopWords()caps them to 4(for
api.openai.com) but never omits the field entirely. Settingstop: []in config does not help —the field is overwritten from the template before the request is sent. The fix is to clear
stoptoundefinedinside the existingisOSeriesOrGpt5PlusModelbranch, which already handles the otherAPI differences for these models.
Root cause
OpenAI._convertArgs()atcore/llm/llms/OpenAI.ts:284setsfinalOptions.stopfrom the autocompletetemplate before the model-capability branch:
OpenAI.modifyChatBody()atcore/llm/llms/OpenAI.ts:440does the same for the adapter path.packages/openai-adapters/src/apis/OpenAI.ts:70has a parallel block for the official OpenAI APIadapter that also does not clear
stop.isOSeriesOrGpt5PlusModel(line 221-223) already matchesall affected models — no new model detection is needed.
Changes
core/llm/llms/OpenAI.ts: addfinalOptions.stop = undefinedas the first statement inside theisOSeriesOrGpt5PlusModelbranch in both_convertArgs()andmodifyChatBody().packages/openai-adapters/src/apis/OpenAI.ts: stripstopinOpenAIApi.modifyChatBody()via anew
isOSeriesOrGpt5Pluspredicate (/^o[0-9]/or/gpt-[5-9]/i, soopenchatdoesn't match)that runs for all hosts, not just
api.openai.com— Azure deployments route throughAzureApi.modifyChatBody() → super.modifyChatBody()and previously kept sendingstop. Thepredicate matches the core path's
gpt-[5-9]definition (gpt-6, gpt-7-turbo, etc.), wider thanthe official-API block's
includes("gpt-5")check.What this doesn't change
getMaxStopWords()is unchanged — it still serves providers that accept stop tokens.OpenAI._convertArgsResponses()is unchanged — the Responses API path does not expose astopfield.stopis still populated.
Azure.ts(core) setsuseOpenAIAdapterFor: [], so it routes throughOpenAI.modifyChatBody(); the adapter-sideAzureApiinherits the new model-based strip fromOpenAIApi.modifyChatBody(). No change to either Azure class is needed.max_completion_tokensconversion stays gated to the official OpenAI API, exactly as before.requestOptions.extraBodyProperties.stop: nullnoted in the issue continues to workbut is no longer necessary for standard deployments.
Checklist
Screen recording or screenshot
Before (gpt-5-nano autocomplete request body):
{ "model": "gpt-5-nano", "stop": ["<|fim_suffix|>", "\n\n", ...], "max_completion_tokens": 256 }After:
{ "model": "gpt-5-nano", "max_completion_tokens": 256 }N/A — no UI change. Error disappears from the network tab.
Tests
Vitest (core/llm/llms/OpenAI.vitest.ts):
cd core && npx vitest run llm/llms/OpenAI.vitest.ts— 11 tests pass, 0 failures.stopis undefined in request body.stopis undefined in request body.stop.Vitest (packages/openai-adapters):
cd packages/openai-adapters && npx vitest run src/test/openai-adapter.vitest.ts src/test/main.test.ts— 25 tests pass, 0 failures (20 existing + 5 new).stop; gpt-4o on Azure-style apiBase keepsstop; gpt-6 on a non-official host stripsstopwithout the official-API conversions;openchatkeepsstop(predicate guard).Jest (core/llm/llms/OpenAI.test.ts):
isOSeriesOrGpt5PlusModel()model detection logic. No new assertions needed for this change.Prettier:
prettier --write.Summary by cubic
Omit the
stopparameter for o-series andgpt-5+models to prevent HTTP 400 errors and restore chat/autocomplete. Applies to both core and adapter paths, including Azure-style endpoints.core/llm/llms/OpenAI.ts: clearstopin_convertArgs()andmodifyChatBody()whenisOSeriesOrGpt5PlusModelis true.packages/openai-adapters/src/apis/OpenAI.ts: stripstopfor o-series andgpt-5+on all hosts; keep official-API-only conversions unchanged.stop), gpt-4o (keepsstop), Azure-style endpoints, non-official hosts (gpt-6 strips onlystop), and guard non-matching models likeopenchat.Written for commit c854a3e. Summary will update on new commits.