Repository navigation
fix(providers): retry OpenAI chat completions with max_completion_tokens when max_tokens is rejected - #723
Open
orshih6 wants to merge 1 commit into
Open
fix(providers): retry OpenAI chat completions with max_completion_tokens when max_tokens is rejected#723orshih6 wants to merge 1 commit into
orshih6 wants to merge 1 commit into
Conversation
…ens when max_tokens is rejected
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.
OpenAIProvider decides between
max_tokensandmax_completion_tokensby matching the model name (gpt-5+,o1/o3/o4). Names that don't match still getmax_tokens. That covers fine-tunes (ft:gpt-5...), prefixed or proxy model ids, and any future family. Newer models reject that with a 400: "Unsupported parameter: 'max_tokens' is not supported with this model. Use 'max_completion_tokens' instead." The whole turn then fails.This change keeps the name-based choice. When the Chat Completions request fails and the error detail says
max_tokensis unsupported, the provider moves the value tomax_completion_tokensand resends once. Any other error, or a second failure, is thrown as before. The request code is now inside a small loop, which is why most of the diff is re-indentation.Tests: two new cases in
tests/providers/OpenAIProvider.test.tsmock fetch. One returns the unsupported-parameter 400 for a fine-tuned model id. It checks that the request is resent withmax_completion_tokensand withoutmax_tokens. That test fails without the fix. The other checks that a different 400 is not retried. The OpenAIProvider test files pass, andtsc --noEmitand eslint on the touched files are clean.Note: the model in the report (
gpt-6.1-sol) already matches the name check on current main. This fallback covers the names the check still misses.🤖 Generated with Claude Code
Fixes #717
This change was prepared with an AI coding agent (Claude) and reviewed by me before submitting. I'm happy to make any changes you'd like.