Skip to content

Fix token param handling for official GPT-5 model IDs#950

Merged
PeterDaveHello merged 1 commit intoChatGPTBox-dev:masterfrom
PeterDaveHello:fix-openai-gpt5-token-params
Mar 7, 2026
Merged

Fix token param handling for official GPT-5 model IDs#950
PeterDaveHello merged 1 commit intoChatGPTBox-dev:masterfrom
PeterDaveHello:fix-openai-gpt5-token-params

Conversation

@PeterDaveHello
Copy link
Member

@PeterDaveHello PeterDaveHello commented Mar 7, 2026

Apply max_completion_tokens only to official GPT-5 model IDs.

Keep provider-prefixed names such as openai/gpt-5.2 on the max_tokens path so namespaced model IDs are not treated as official OpenAI GPT-5 identifiers.

Summary by CodeRabbit

Bug Fixes

  • Corrected the GPT-5 model identification pattern to match only models that begin with the specific identifier. Previously, models using provider prefixes or path separators were incorrectly matched, leading to improper token parameter configuration. This update ensures accurate token handling across all model variants and improves API request reliability.

Apply max_completion_tokens only to official GPT-5 model IDs.

Keep provider-prefixed names such as openai/gpt-5.2 on the
max_tokens path so namespaced model IDs are not treated as
official OpenAI GPT-5 identifiers.
@PeterDaveHello PeterDaveHello requested a review from Copilot March 7, 2026 15:59
@qodo-code-review
Copy link
Contributor

Review Summary by Qodo

Fix token parameter handling for official GPT-5 model IDs

🐞 Bug fix

Grey Divider

Walkthroughs

Description
• Fix regex pattern to match only official GPT-5 model IDs
• Exclude provider-prefixed models like openai/gpt-5.2 from max_completion_tokens
• Update test expectations to reflect corrected token parameter handling
Diagram
flowchart LR
  A["Model ID Pattern"] -->|Official GPT-5| B["max_completion_tokens"]
  A -->|Provider-prefixed| C["max_tokens"]
  D["Regex: /^gpt-5([.-]|$)/"] -->|Matches| B
  E["openai/gpt-5.2"] -->|Excluded| C
Loading

Grey Divider

File Changes

1. src/services/apis/openai-token-params.mjs 🐞 Bug fix +1/-1

Restrict GPT-5 pattern to official model IDs only

• Changed regex pattern from /(^|\/)gpt-5([.-]|$)/ to /^gpt-5([.-]|$)/
• Removes support for provider-prefixed model names in the pattern
• Ensures only official OpenAI GPT-5 identifiers use max_completion_tokens

src/services/apis/openai-token-params.mjs


2. tests/unit/services/apis/openai-token-params.test.mjs 🧪 Tests +2/-2

Update test for provider-prefixed GPT-5 models

• Updated test name to clarify provider-prefixed models use max_tokens
• Changed expected token parameter from max_completion_tokens to max_tokens for openai/gpt-5.2
• Aligns test expectations with corrected regex behavior

tests/unit/services/apis/openai-token-params.test.mjs


Grey Divider

Qodo Logo

@qodo-code-review
Copy link
Contributor

qodo-code-review bot commented Mar 7, 2026

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

ⓘ The new review experience is currently in Beta. Learn more

Grey Divider

Qodo Logo

@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refines the token parameter handling for OpenAI models, specifically addressing how 'max_completion_tokens' and 'max_tokens' are applied based on model identification. The changes ensure that only official GPT-5 model IDs trigger the 'max_completion_tokens' logic, while provider-prefixed model names correctly fall back to using 'max_tokens', preventing unintended behavior with third-party model variations.

Highlights

  • GPT-5 Model ID Matching: The regular expression used to identify official GPT-5 chat completion models has been refined to prevent matching provider-prefixed model names.
  • Token Parameter Handling: Logic now correctly distinguishes between 'max_completion_tokens' for official GPT-5 models and 'max_tokens' for provider-prefixed models, ensuring accurate parameter application.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • src/services/apis/openai-token-params.mjs
    • Updated the 'GPT5_CHAT_COMPLETIONS_MODEL_PATTERN' regex to specifically match official GPT-5 model IDs by removing the leading '(/^|/)' group.
  • tests/unit/services/apis/openai-token-params.test.mjs
    • Renamed the test case from 'uses max_completion_tokens for provider-prefixed gpt-5.x models' to 'uses max_tokens for provider-prefixed gpt-5.x model names'.
    • Modified the assertion within the test to expect 'max_tokens: 2048' instead of 'max_completion_tokens: 2048' for provider-prefixed GPT-5 models.
Activity
  • No human activity has been recorded on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 7, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b5bd4b64-d6fe-4d5d-ba4d-d90f3de9f86b

📥 Commits

Reviewing files that changed from the base of the PR and between fade0ea and fdfad4f.

📒 Files selected for processing (2)
  • src/services/apis/openai-token-params.mjs
  • tests/unit/services/apis/openai-token-params.test.mjs

📝 Walkthrough

Walkthrough

The GPT-5 model pattern matching logic in the OpenAI token parameters service was narrowed to require strings starting with "gpt-5" instead of matching any position. The corresponding test was updated to reflect this stricter matching behavior.

Changes

Cohort / File(s) Summary
OpenAI Token Parameters
src/services/apis/openai-token-params.mjs, tests/unit/services/apis/openai-token-params.test.mjs
Narrowed GPT-5 model pattern matching to require "gpt-5" prefix instead of containing it at any path segment. Updated test expectation from max_completion_tokens to max_tokens for provider-prefixed models.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Suggested labels

Review effort 2/5

Suggested reviewers

  • kmk142789

Poem

🐰 A pattern refined, oh what a sight!
GPT-5 now starts just right,
No more wandering through paths untrue,
Token tests updated—a hop of two!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: fixing token parameter handling specifically for official GPT-5 model IDs, which is exactly what the PR accomplishes by narrowing the pattern matching.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refines the logic for identifying official GPT-5 model IDs by adjusting the regular expression. The change correctly ensures that only model IDs that start with gpt-5 are matched, excluding namespaced IDs like openai/gpt-5.2. The test suite has been updated accordingly to verify the new behavior. The implementation is sound and effectively achieves the stated goal.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates OpenAI chat-completions token-limit parameter selection so max_completion_tokens is only used for official (non-namespaced) GPT‑5 model IDs, keeping provider-prefixed model names (e.g. openai/gpt-5.2) on the max_tokens path.

Changes:

  • Tighten GPT‑5 model matching to only model IDs starting with gpt-5 (no provider prefix).
  • Update unit test coverage/expectations for provider-prefixed GPT‑5 model names to use max_tokens.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/services/apis/openai-token-params.mjs Adjusts the GPT‑5 model regex so provider-prefixed model IDs no longer trigger max_completion_tokens.
tests/unit/services/apis/openai-token-params.test.mjs Updates the provider-prefixed GPT‑5 test to expect max_tokens instead of max_completion_tokens.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@PeterDaveHello
Copy link
Member Author

cc #922

@PeterDaveHello PeterDaveHello merged commit d523354 into ChatGPTBox-dev:master Mar 7, 2026
7 checks passed
@PeterDaveHello PeterDaveHello deleted the fix-openai-gpt5-token-params branch March 7, 2026 16:09
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