Skip to content

fix: use max_completion_tokens for gpt-5/o-series models - #6

Open
mogliabr wants to merge 1 commit into
papi-ai:mainfrom
mogliabr:fix/max-completion-tokens
Open

fix: use max_completion_tokens for gpt-5/o-series models#6
mogliabr wants to merge 1 commit into
papi-ai:mainfrom
mogliabr:fix/max-completion-tokens

Conversation

@mogliabr

Copy link
Copy Markdown

Problem

The Chat Completions API rejects max_tokens on reasoning models — gpt-5 and the o-series — returning 400 Unsupported parameter: 'max_tokens'. These models require max_completion_tokens instead.

buildPayload() currently always sends max_tokens when maxTokens is set:

$payload['max_tokens'] = $options['maxTokens'];

Fix

Select the token-limit field based on the model family prefix:

$payload[$this->tokenLimitKey($model)] = $options['maxTokens'];

tokenLimitKey() returns max_completion_tokens for gpt-5, o1, o3, o4 (matched by prefix, so future gpt-5.x releases are covered without changes) and max_tokens for everything else.

Tests

Added coverage for gpt-5.6-luna and o3-mini asserting max_completion_tokens is emitted and max_tokens is absent. The existing gpt-4-turbo test still asserts max_tokens, confirming classic chat models are unaffected.

composer lint and composer test (71 passed) pass locally.

The Chat Completions API rejects max_tokens on reasoning models
(gpt-5 and the o-series) and requires max_completion_tokens instead.
buildPayload() now selects the token-limit field based on the model
family prefix, so future gpt-5.x releases are covered without further
changes.

Adds coverage for gpt-5.6-luna and o3-mini.
@mogliabr
mogliabr force-pushed the fix/max-completion-tokens branch from 3ded037 to 46911a0 Compare August 18, 2026 16:14
@mogliabr

Copy link
Copy Markdown
Author

I get this bug using lib my personal fix can be affected by furure updates so i sended the path. Thanks for created it. Fist time using github im only subversion and cvs user for commit. Get learn how use git hub.

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.

1 participant