fix: use max_completion_tokens for OpenAI chat completions - #99
Conversation
Summary of ChangesHello, 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
Changelog
Activity
Using Gemini Code AssistThe 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
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 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
|
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #99 +/- ##
=========================================
Coverage 92.48% 92.48%
Complexity 1937 1937
=========================================
Files 77 77
Lines 6849 6849
=========================================
Hits 6334 6334
Misses 515 515
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
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_tokenstomax_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.
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>
79a96ad to
e7c347e
Compare
There was a problem hiding this comment.
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.
Summary
OpenAI deprecated
max_tokensfor newer models (GPT-4o, o3, etc.) in favor ofmax_completion_tokens. Sending the old parameter causes:Unsupported parameter: 'max_tokens' is not supported with this model. Use 'max_completion_tokens' instead.Changes
OpenAiProviderto sendmax_completion_tokensinstead ofmax_tokensChatOptions::maxTokens) is unchanged — the mapping happens at the HTTP payload levelTest plan