Skip to content

fix(providers): retry OpenAI chat completions with max_completion_tokens when max_tokens is rejected - #723

Open
orshih6 wants to merge 1 commit into
autohandai:mainfrom
orshih6:contribot/issue-717
Open

orshih6 wants to merge 1 commit into
autohandai:mainfrom
orshih6:contribot/issue-717

Conversation

@orshih6

@orshih6 orshih6 commented Oct 30, 2026

Copy link
Copy Markdown

OpenAIProvider decides between max_tokens and max_completion_tokens by matching the model name (gpt-5+, o1/o3/o4). Names that don't match still get max_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_tokens is unsupported, the provider moves the value to max_completion_tokens and 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.ts mock fetch. One returns the unsupported-parameter 400 for a fine-tuned model id. It checks that the request is resent with max_completion_tokens and without max_tokens. That test fails without the fix. The other checks that a different 400 is not retried. The OpenAIProvider test files pass, and tsc --noEmit and 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Auto] session_failure: The request was malformed and could not be processed. Unsupported parameter: 'ma

1 participant