Skip to content

fix: use max_completion_tokens for OpenAI chat completions - #99

Merged
CybotTM merged 1 commit into
mainfrom
fix/openai-max-completion-tokens
Mar 6, 2026
Merged

fix: use max_completion_tokens for OpenAI chat completions#99
CybotTM merged 1 commit into
mainfrom
fix/openai-max-completion-tokens

Conversation

@CybotTM

@CybotTM CybotTM commented Mar 6, 2026

Copy link
Copy Markdown
Member

Summary

OpenAI deprecated max_tokens for newer models (GPT-4o, o3, etc.) in favor of max_completion_tokens. Sending the old parameter causes: Unsupported parameter: 'max_tokens' is not supported with this model. Use 'max_completion_tokens' instead.

Changes

  • Updated all 4 chat completion payload locations in OpenAiProvider to send max_completion_tokens instead of max_tokens
  • The internal options API (ChatOptions::maxTokens) is unchanged — the mapping happens at the HTTP payload level
  • Updated integration and E2E test assertions to match the new payload key

Test plan

  • All 2706 tests pass locally
  • Manual: test OpenAI model play in provider module

Copilot AI review requested due to automatic review settings March 6, 2026 11:07
@gemini-code-assist

Copy link
Copy Markdown

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 addresses an incompatibility issue with newer OpenAI models by updating the API parameter for maximum completion tokens. The change ensures that the application can successfully interact with the latest OpenAI models without encountering deprecation errors, while preserving the internal API for existing configurations. This is a targeted fix for the OpenAI provider, with corresponding test updates to validate the change.

Highlights

  • OpenAI API Compatibility: Replaced the deprecated max_tokens parameter with max_completion_tokens in OpenAI API payloads to ensure compatibility with newer models like GPT-4o.
  • Error Resolution: Fixed the 'Unsupported parameter: 'max_tokens' is not supported with this model. Use 'max_completion_tokens' instead.' error encountered with modern OpenAI models.
  • Backward Compatibility: Maintained the internal option name (max_tokens) for backward compatibility, only changing the outgoing API payload key.
  • Provider Scope: Changes are limited to the OpenAI provider; other providers such as Ollama, Gemini, and Anthropic remain unaffected.
  • Test Updates: Updated E2E and integration tests to reflect the change in the expected OpenAI API parameter name.
Changelog
  • Classes/Provider/OpenAiProvider.php
    • Updated max_tokens to max_completion_tokens in the chatCompletion method payload.
    • Updated max_tokens to max_completion_tokens in the chatCompletionWithTools method payload.
    • Updated max_tokens to max_completion_tokens in the analyzeImage method payload.
    • Updated max_tokens to max_completion_tokens in the streamChatCompletion method payload.
  • Tests/E2E/ChatCompletionWorkflowTest.php
    • Adjusted assertion from max_tokens to max_completion_tokens in the chatWithOptionsWorkflow test.
  • Tests/Integration/Service/LlmServiceManagerIntegrationTest.php
    • Adjusted assertion from max_tokens to max_completion_tokens in the chatWithOptionsPassesThemToProvider test.
Activity
  • All 2627 unit/integration/e2e tests passed locally.
  • CI is expected to pass.
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.

@github-actions github-actions Bot added tests Test-related changes providers LLM provider changes labels Mar 6, 2026
@github-actions

github-actions Bot commented Mar 6, 2026

Copy link
Copy Markdown
Contributor

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Automated approval for solo maintainer project

This PR has passed all automated quality gates:

  • ✅ Static analysis (PHPStan)
  • ✅ Code style (PHP-CS-Fixer)
  • ✅ Unit & functional tests
  • ✅ Security scanning
  • ✅ Dependency review

See SECURITY_CONTROLS.md for compensating controls documentation.

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

Copy link
Copy Markdown

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 correctly addresses the deprecation of max_tokens in the OpenAI API by replacing it with max_completion_tokens. The changes are consistently applied across all relevant methods in OpenAiProvider, and the tests have been updated accordingly to reflect this change.

@codecov

codecov Bot commented Mar 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.48%. Comparing base (ed2b7ec) to head (e7c347e).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##               main      #99   +/-   ##
=========================================
  Coverage     92.48%   92.48%           
  Complexity     1937     1937           
=========================================
  Files            77       77           
  Lines          6849     6849           
=========================================
  Hits           6334     6334           
  Misses          515      515           
Flag Coverage Δ
unit 92.48% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
Classes/Provider/OpenAiProvider.php 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the OpenAI provider’s Chat Completions request payload to use max_completion_tokens instead of the deprecated max_tokens, resolving incompatibilities with newer OpenAI models while keeping the internal option name (max_tokens) unchanged for backward compatibility.

Changes:

  • Switch OpenAI Chat Completions payload field from max_tokens to max_completion_tokens (including tools, vision, and streaming variants).
  • Update E2E and integration tests to assert the new payload key.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
Classes/Provider/OpenAiProvider.php Updates OpenAI chat/vision/stream payloads to send max_completion_tokens.
Tests/E2E/ChatCompletionWorkflowTest.php Adjusts assertions to expect max_completion_tokens in captured request payload.
Tests/Integration/Service/LlmServiceManagerIntegrationTest.php Adjusts assertions to expect max_completion_tokens in captured request payload.

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

Comment thread Tests/Integration/Service/LlmServiceManagerIntegrationTest.php
OpenAI deprecated the max_tokens parameter for newer models (GPT-4o, o3,
etc.) in favor of max_completion_tokens. This change updates all four
chat completion payload locations in OpenAiProvider to use the new
parameter name.

The internal options API still accepts max_tokens as the option key,
which is mapped to max_completion_tokens in the HTTP payload.

Signed-off-by: Sebastian Mendel <info@sebastianmendel.de>
@CybotTM
CybotTM force-pushed the fix/openai-max-completion-tokens branch from 79a96ad to e7c347e Compare March 6, 2026 11:13

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Automated approval for solo maintainer project

This PR has passed all automated quality gates:

  • ✅ Static analysis (PHPStan)
  • ✅ Code style (PHP-CS-Fixer)
  • ✅ Unit & functional tests
  • ✅ Security scanning
  • ✅ Dependency review

See SECURITY_CONTROLS.md for compensating controls documentation.

@CybotTM
CybotTM enabled auto-merge March 6, 2026 11:14
@CybotTM
CybotTM added this pull request to the merge queue Mar 6, 2026
Merged via the queue into main with commit 1283065 Mar 6, 2026
39 checks passed
@CybotTM
CybotTM deleted the fix/openai-max-completion-tokens branch March 6, 2026 11:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

providers LLM provider changes tests Test-related changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants