fix(ai): map Anthropic max_tokens to OpenAI max_completion_tokens#225
Open
dimakis wants to merge 2 commits into
Open
fix(ai): map Anthropic max_tokens to OpenAI max_completion_tokens#225dimakis wants to merge 2 commits into
dimakis wants to merge 2 commits into
Conversation
|
Unsigned commits: b1f811f. Please sign your commits. |
OpenAI's GPT-5.x and reasoning models (o1/o3) reject the legacy `max_tokens` parameter in Chat Completions requests, returning: "Unsupported parameter: 'max_tokens' is not supported with this model. Use 'max_completion_tokens' instead." The `anthropic_to_openai` request transform was mapping Anthropic's `max_tokens` field to OpenAI's `max_tokens`, which works for older models (GPT-4.1, GPT-3.5) but fails on all current frontier models. `max_completion_tokens` is backwards-compatible with older models that still accept `max_tokens`, so this change is safe to apply unconditionally. Signed-off-by: Dimitri Saridakis <dimitri.saridakis@gmail.com> Signed-off-by: dimakis <dimitri.saridakis@gmail.com>
b1f811f to
6b4e9a9
Compare
leseb
approved these changes
Jul 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
anthropic_to_openairequest transform maps Anthropic'smax_tokensto OpenAI'smax_tokensin Chat Completions requestsmax_tokens, returning: "Unsupported parameter: 'max_tokens' is not supported with this model. Use 'max_completion_tokens' instead."max_completion_tokensinstead, which is backwards-compatible with older modelsContext
OpenAI has three different token limit parameters across their APIs:
max_tokens/v1/messagesmax_completion_tokens/v1/chat/completionsmax_output_tokens/v1/responsesThe
max_completion_tokensparameter was introduced with the o1 reasoning models to distinguish between reasoning tokens and output tokens. GPT-5.x models continued this convention, rejecting the legacymax_tokensentirely.This fix addresses the Chat Completions path only. The Responses API (
/v1/responses) usesmax_output_tokensand would need separate translation logic.Evidence
Direct API error (GPT-5.5 via Chat Completions through praxis-proxy):
OpenAI API reference (developers.openai.com/api/docs/api-reference/evals):
Backwards compatibility:
max_completion_tokensis accepted by both legacy models (GPT-4.1, GPT-3.5-turbo) and current frontier models (GPT-5.x, o3). Safe to apply unconditionally.Verification
Tested locally with praxis-proxy proxying Anthropic-format requests to OpenAI:
Existing unit tests updated and passing (14/14).
Test plan