fix: remap max_completion_tokens to max_tokens for OpenAI-compatible providers#7765
Merged
jamadeo merged 2 commits intoblock:mainfrom Mar 11, 2026
Merged
Conversation
…providers When using OpenAI-compatible providers like Mistral via the declarative provider system, the OpenAI-specific parameter max_completion_tokens (used for O-series models) is not recognized and causes 422 errors. This adds a sanitize_request_for_compat method to OpenAiProvider that remaps max_completion_tokens to max_tokens for any non-native OpenAI provider, ensuring compatibility with Mistral and other OpenAI-compatible APIs. Closes block#7762 Signed-off-by: fre <[email protected]>
jamadeo
reviewed
Mar 10, 2026
Collaborator
jamadeo
left a comment
There was a problem hiding this comment.
True for mistral but always true for others? Maybe safer for now to check explicitly for mistral?
I'm looking at pi's implementation here and thinking we're missing a fair bit of openai compatibility nuances.
I wonder if the declarative provider configs just need more of these options
Collaborator
|
(forgot to cite my sources) I do not know if pi is the thing to reference here, but that seems pretty thorough |
Contributor
Author
|
Good call — narrowed it to Mistral/Groq for safety in this PR. Long-term I think we should move these mappings into the declarative config |
Address review feedback: instead of remapping max_completion_tokens to max_tokens for all non-OpenAI providers, use an explicit allowlist of providers known to reject max_completion_tokens. This prevents silently breaking future providers that may support the field natively. Signed-off-by: fre <[email protected]>
jamadeo
approved these changes
Mar 11, 2026
lifeizhou-ap
added a commit
that referenced
this pull request
Mar 12, 2026
* main: (270 commits) test(acp): align provider and server test parity (#7822) fix(acp): register MCP extensions when resuming a session (#7806) fix(goose): load .gitignore in prompt_manager for hint file filtering (#7795) fix: remap max_completion_tokens to max_tokens for OpenAI-compatible providers (#7765) fix(openai): preserve Responses API tool call/output linkage (#7759) chore(deps): bump @hono/node-server from 1.19.9 to 1.19.11 in /evals/open-model-gym/mcp-harness (#7687) fix: return ContextLengthExceeded when prompt exceeds effective KV cache size (#7815) feat: MCP Roots support (#7790) fix(google): use `includeThoughts/part.thought` for thinking handling (#7593) refactor: simplify tokenizer initialization — remove unnecessary Result wrapper (#7744) Fix model selector showing wrong model in tabs (#7784) Stop collecting goosed stderr after startup (#7814) fix: avoid word splitting by space for windows shell commands (#7781) (#7810) Simplify and make it not break on linux (#7813) Add preferred microphone selection (#7805) Remove dependency on posthog-rs (#7811) feat: load hints in nested subdirs (#7772) feat(acp): add read tool and delegate filesystem I/O to ACP clients (#7668) Support secret interpolation in streamable HTTP extension URLs (#7782) More logging for command injection classifier model training (#7779) ...
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
When using OpenAI-compatible providers like Mistral via the declarative provider system, the OpenAI-specific parameter
max_completion_tokens(used for O-series models) is not recognized and causes 422 errors.Root Cause
OpenAiProvideris used by both native OpenAI and declarative OpenAI-compatible providers (Mistral, Groq, etc.). Thecreate_request()function setsmax_completion_tokensfor O-series models, but this parameter is not recognized by non-OpenAI APIs like Mistral, which expectmax_tokensinstead.Fix
Added
sanitize_request_for_compat()method toOpenAiProviderthat remapsmax_completion_tokenstomax_tokensfor any non-native OpenAI provider (name != "openai"). Applied in thestreamcode path (the active chat completions path). Ifmax_tokensalready exists, the existing value is preserved.Validation
cargo fmtcleancargo clippycleanCloses #7762