Skip to content

fix(openai): omit stop parameter for o-series and gpt-5+ models#12592

Open
rodboev wants to merge 1 commit into
continuedev:mainfrom
rodboev:pr/strip-stop-o-series
Open

fix(openai): omit stop parameter for o-series and gpt-5+ models#12592
rodboev wants to merge 1 commit into
continuedev:mainfrom
rodboev:pr/strip-stop-o-series

Conversation

@rodboev

@rodboev rodboev commented Jun 10, 2026

Copy link
Copy Markdown

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 autocomplete
request. The autocomplete template always supplies stop tokens, and getMaxStopWords() caps them to 4
(for api.openai.com) but never omits the field entirely. Setting stop: [] in config does not help —
the field is overwritten from the template before the request is sent. The fix is to clear stop to
undefined inside the existing isOSeriesOrGpt5PlusModel branch, which already handles the other
API differences for these models.

Root cause

OpenAI._convertArgs() at core/llm/llms/OpenAI.ts:284 sets finalOptions.stop from the autocomplete
template before the model-capability branch:

finalOptions.stop = options.stop?.slice(0, this.getMaxStopWords());  // line 284

if (this.isOSeriesOrGpt5PlusModel(options.model)) {
  // handles max_tokens and messages — but not stop
}

OpenAI.modifyChatBody() at core/llm/llms/OpenAI.ts:440 does the same for the adapter path.
packages/openai-adapters/src/apis/OpenAI.ts:70 has a parallel block for the official OpenAI API
adapter that also does not clear stop. isOSeriesOrGpt5PlusModel (line 221-223) already matches
all affected models — no new model detection is needed.

Changes

  • core/llm/llms/OpenAI.ts: add finalOptions.stop = undefined as the first statement inside the
    isOSeriesOrGpt5PlusModel branch in both _convertArgs() and modifyChatBody().
  • packages/openai-adapters/src/apis/OpenAI.ts: strip stop in OpenAIApi.modifyChatBody() via a
    new isOSeriesOrGpt5Plus predicate (/^o[0-9]/ or /gpt-[5-9]/i, so openchat doesn't match)
    that runs for all hosts, not just api.openai.com — Azure deployments route through
    AzureApi.modifyChatBody() → super.modifyChatBody() and previously kept sending stop. The
    predicate matches the core path's gpt-[5-9] definition (gpt-6, gpt-7-turbo, etc.), wider than
    the 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 a stop field.
  • All non-o-series, non-gpt-5+ models (gpt-4, gpt-4o, gpt-4-turbo, etc.) are unaffected; their stop
    is still populated.
  • Azure — Azure.ts (core) sets useOpenAIAdapterFor: [], so it routes through
    OpenAI.modifyChatBody(); the adapter-side AzureApi inherits the new model-based strip from
    OpenAIApi.modifyChatBody(). No change to either Azure class is needed.
  • The max_completion_tokens conversion stays gated to the official OpenAI API, exactly as before.
  • The workaround requestOptions.extraBodyProperties.stop: null noted in the issue continues to work
    but is no longer necessary for standard deployments.

Checklist

  • I've read the contributing guide
  • The relevant docs, if any, have been updated or created
  • The relevant tests, if any, have been updated or created

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.ts11 tests pass, 0 failures.
  • Coverage: 8 existing tests (streamChat/chat/complete, O1 models, tools, max tokens, embeddings) + 3 new cases:
    • gpt-5-nano streamChat: verifies stop is undefined in request body.
    • o3-mini streamChat: verifies stop is undefined in request body.
    • gpt-4o streamChat (regression): verifies non-o-series models still include stop.

Vitest (packages/openai-adapters):

  • cd packages/openai-adapters && npx vitest run src/test/openai-adapter.vitest.ts src/test/main.test.ts25 tests pass, 0 failures (20 existing + 5 new).
  • New coverage: o3 and gpt-5 on an Azure-style apiBase strip stop; gpt-4o on Azure-style apiBase keeps stop; gpt-6 on a non-official host strips stop without the official-API conversions; openchat keeps stop (predicate guard).

Jest (core/llm/llms/OpenAI.test.ts):

  • Tests isOSeriesOrGpt5PlusModel() model detection logic. No new assertions needed for this change.

Prettier:

  • All modified files pass formatting checks after prettier --write.

Summary by cubic

Omit the stop parameter for o-series and gpt-5+ models to prevent HTTP 400 errors and restore chat/autocomplete. Applies to both core and adapter paths, including Azure-style endpoints.

  • Bug Fixes
    • Core core/llm/llms/OpenAI.ts: clear stop in _convertArgs() and modifyChatBody() when isOSeriesOrGpt5PlusModel is true.
    • Adapter packages/openai-adapters/src/apis/OpenAI.ts: strip stop for o-series and gpt-5+ on all hosts; keep official-API-only conversions unchanged.
    • Tests: add coverage for gpt-5-nano and o3-mini (no stop), gpt-4o (keeps stop), Azure-style endpoints, non-official hosts (gpt-6 strips only stop), and guard non-matching models like openchat.

Written for commit c854a3e. Summary will update on new commits.

Review in cubic

@rodboev rodboev requested a review from a team as a code owner June 10, 2026 19:59
@rodboev rodboev requested review from sestinj and removed request for a team June 10, 2026 19:59
@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jun 10, 2026

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 4 files

Re-trigger cubic

@rodboev rodboev force-pushed the pr/strip-stop-o-series branch from febe921 to c854a3e Compare June 10, 2026 20:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L This PR changes 100-499 lines, ignoring generated files.

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

Unable to remove "stop" parameter from autocomplete request for gpt-5-nano

1 participant