Skip to content

fix(openai): support max_completion_tokens for reasoning models#80

Merged
maxchang3 merged 2 commits intodev/releasefrom
fix/max-tokens
Apr 11, 2026
Merged

fix(openai): support max_completion_tokens for reasoning models#80
maxchang3 merged 2 commits intodev/releasefrom
fix/max-tokens

Conversation

@maxchang3
Copy link
Copy Markdown
Collaborator

@maxchang3 maxchang3 commented Mar 30, 2026

Fixes raycast/extensions#26761

Background

According to the OpenAI docs, reasoning models (e.g. o1, o3, gpt-5) require max_completion_tokens, and max_tokens is not supported:

Currently, our extension uses max_tokens for all models, which leads to incompatibility with reasoning models.

For OpenAI-compatible providers, behavior is inconsistent:

  • Some still expect max_tokens
  • Others follow OpenAI’s newer convention (max_completion_tokens)

This creates ambiguity when integrating with different providers.


Changes

  • Introduced model-based detection for reasoning models using pattern (From Dify’s approach):

    /^(o1|o3|gpt-5)/i
  • Added endpoint-aware logic:

    • When using the official OpenAI endpoint (https://api.openai.com/)
    • AND the model matches a reasoning model
    • Automatically switch to max_completion_tokens
  • Added a user-configurable option:

    • forceMaxCompletionTokens
    • Allows forcing max_completion_tokens regardless of endpoint/model
    • Useful for OpenAI-compatible providers that follow the new convention

@maxchang3 maxchang3 changed the title feat(openai): support max_completion_tokens for reasoning models feat(openai): support max_completion_tokens for reasoning models Mar 30, 2026
@maxchang3 maxchang3 changed the title feat(openai): support max_completion_tokens for reasoning models fix(openai): support max_completion_tokens for reasoning models Mar 30, 2026
@maxchang3
Copy link
Copy Markdown
Collaborator Author

For this PR, please use Squash and merge

@maxchang3 maxchang3 marked this pull request as ready for review March 31, 2026 07:02
@maxchang3
Copy link
Copy Markdown
Collaborator Author

maxchang3 commented Mar 31, 2026

Although current models seem to only accept max_completion_tokens, I'll keep this regex to support OpenAI-compatible providers or third-party platforms that also expose OpenAI models, in case it's still needed.

@maxchang3 maxchang3 merged commit 337b107 into dev/release Apr 11, 2026
3 checks passed
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.

2 participants