fix(openai): non-compatible providers send correct max_tokens field#57
Open
fix(openai): non-compatible providers send correct max_tokens field#57
Conversation
0e9c2d9 to
4b59f4f
Compare
…field DeepSeek and Mistral are not fully OpenAI-compatible but delegated to CompatibleProvider.Completion(), which unconditionally mapped MaxTokens to max_completion_tokens on the wire. Both APIs expect max_tokens. Add ChatCompletionRequestTransform hook to CompatibleConfig (Strategy pattern) that lets providers adjust the SDK request after convertParams builds it. DeepSeek and Mistral supply transforms that swap max_completion_tokens back to max_tokens and clear unsupported fields. Move Mistral's user/reasoning_effort stripping from preprocessParams (CompletionParams level) to transformRequest (SDK request level) where it correctly prevents the fields from being serialized. Add FakeCompletionServer test helper and wire-level tests that capture actual JSON request bodies to assert correct field names on the wire.
4b59f4f to
6aa62c7
Compare
javiermtorres
approved these changes
Feb 27, 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
CompatibleProvider.Completion()which mapsMaxTokens→max_completion_tokenson the wire. Both APIs actually expectmax_tokens, meaning the token limit was silently dropped.ChatCompletionRequestTransformhook toCompatibleConfig(Strategy pattern) so providers can adjust the SDK request afterconvertParamsbuilds it.max_completion_tokens→max_tokensand clear unsupported fields.user/reasoning_effortstripping frompreprocessParamstotransformRequestwhere it operates on the actual wire request.Context
Inspired by any-llm#865 which addressed the same
max_tokensvsmax_completion_tokensissue in the Python port. The Go approach differs: rather than changing the base compatible provider, we keepmax_completion_tokensas the correct default (per OpenAI spec) and let non-compatible providers opt into transforming their requests.Test plan
httptest.NewServercapture actual JSON bodies and assert field namesmax_completion_tokens(notmax_tokens)max_tokens(notmax_completion_tokens)max_tokens(notmax_completion_tokens)userandreasoning_effortfrom wire requests-race