fix(openai): send max_completion_tokens for gpt-5 models - #61
Open
hlubek wants to merge 1 commit into
Open
Conversation
gpt-5-class models reject max_tokens with HTTP 400 and require max_completion_tokens instead. needsMaxCompletionTokens already detects o-series and 4o models; extend it to gpt-5 (gpt-5, gpt-5-mini, gpt-5.4-2026-03-05, ...). Both SetOption and the PrepareRequest variants route through this single predicate, so every request path is covered by the one change. Adds table cases for gpt-5 detection plus a PrepareRequest test asserting the request body carries max_completion_tokens and never max_tokens. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
Reviewer's GuideExtends OpenAI provider handling so that all gpt-5* models use max_completion_tokens instead of max_tokens, and adds tests to verify detection and request preparation behavior. Sequence diagram for OpenAIProvider request preparation using max_completion_tokens for gpt-5 modelssequenceDiagram
actor Caller
participant OpenAIProvider
Caller->>OpenAIProvider: SetOption(max_tokens)
OpenAIProvider->>OpenAIProvider: needsMaxCompletionTokens()
alt model is gpt-5*
OpenAIProvider->>OpenAIProvider: store max_completion_tokens
else other model
OpenAIProvider->>OpenAIProvider: store max_tokens
end
Caller->>OpenAIProvider: PrepareRequest()
OpenAIProvider->>OpenAIProvider: needsMaxCompletionTokens()
alt model is gpt-5*
OpenAIProvider-->>Caller: request body with max_completion_tokens
else other model
OpenAIProvider-->>Caller: request body with max_tokens
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
hlubek
added a commit
to networkteam/sdd
that referenced
this pull request
Jun 16, 2026
Repins the networkteam/gollm replace to 19e75fe, which teaches the OpenAI provider to emit max_completion_tokens for gpt-5-class models (upstream PR teilomillet/gollm#61). Fixes the HTTP 400 that broke OpenAI gpt-5 summary and pre-flight calls (s-tac-t96). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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
gpt-5-class models reject the
max_tokensparameter with HTTP 400 — they requiremax_completion_tokensinstead. Any caller that sets a token budget against a gpt-5 model (e.g.gpt-5,gpt-5-mini,gpt-5.4-2026-03-05) currently gets a 400.Fix
needsMaxCompletionTokens()already recognizes the o-series and4omodels that needmax_completion_tokens; this extends it togpt-5*. BothSetOptionand thePrepareRequestvariants route through that single predicate, so every request path is covered by the one change.Tests
gpt-5,gpt-5-mini, andgpt-5.4-2026-03-05.PrepareRequesttest asserting a gpt-5 request body carriesmax_completion_tokensand nevermax_tokens, with the token budget preserved across the conversion.Summary by Sourcery
Ensure OpenAI provider uses max_completion_tokens for gpt-5-class models instead of max_tokens to avoid API errors.
Tests: