fix: use max_tokens for openai provider with custom base URL (Mistral compatibility)#858
Merged
nicoloboschi merged 1 commit intovectorize-io:mainfrom Apr 7, 2026
Conversation
Mistral (and several other providers) reject 'max_completion_tokens' with a 422 because they haven't adopted the newer OpenAI parameter name. When the openai provider is configured with a custom base_url (e.g. Mistral, Together AI), fall back to the widely-supported 'max_tokens' parameter. Native OpenAI (no custom base_url) and Groq still use 'max_completion_tokens'. Fixes vectorize-io#852
nicoloboschi
added a commit
that referenced
this pull request
Apr 10, 2026
…penAI PR #858 made the openai provider fall back to max_tokens whenever a custom base_url was set, to support Mistral/Together-style endpoints. This regressed two important setups: 1. Reasoning models (GPT-5, o1, o3) reject max_tokens outright with a 400 ("Unsupported parameter: 'max_tokens' is not supported with this model. Use 'max_completion_tokens' instead."). 2. Azure OpenAI is fully OpenAI-API-compatible — it was only classified as "third-party compatible" because it requires a custom base_url. The combination of the two — Azure OpenAI + GPT-5 — is the exact setup the reporter hit in issue #978 and fails connection verification on startup. Fix _max_tokens_param_name() so it: - Always returns max_completion_tokens for reasoning models, regardless of base_url (they only support the new parameter name). - Detects Azure OpenAI endpoints by the *.openai.azure.com hostname and treats them as native OpenAI. The Mistral/Together behavior from #858 is preserved for non-reasoning models on non-Azure custom base URLs. Fixes #978
3 tasks
nicoloboschi
added a commit
that referenced
this pull request
Apr 13, 2026
…penAI (#979) PR #858 made the openai provider fall back to max_tokens whenever a custom base_url was set, to support Mistral/Together-style endpoints. This regressed two important setups: 1. Reasoning models (GPT-5, o1, o3) reject max_tokens outright with a 400 ("Unsupported parameter: 'max_tokens' is not supported with this model. Use 'max_completion_tokens' instead."). 2. Azure OpenAI is fully OpenAI-API-compatible — it was only classified as "third-party compatible" because it requires a custom base_url. The combination of the two — Azure OpenAI + GPT-5 — is the exact setup the reporter hit in issue #978 and fails connection verification on startup. Fix _max_tokens_param_name() so it: - Always returns max_completion_tokens for reasoning models, regardless of base_url (they only support the new parameter name). - Detects Azure OpenAI endpoints by the *.openai.azure.com hostname and treats them as native OpenAI. The Mistral/Together behavior from #858 is preserved for non-reasoning models on non-Azure custom base URLs. Fixes #978
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.
Fixes #852
Problem
When using
HINDSIGHT_API_LLM_PROVIDER=openaiwithHINDSIGHT_API_LLM_BASE_URLpointing to Mistral's API (https://api.mistral.ai/v1), Hindsight crashes on startup duringverify_connectionbecausemax_completion_tokensis sent but Mistral only acceptsmax_tokens, returning a 422:Solution
Add
_max_tokens_param_name()method that selects the correct parameter name based on provider and base URL:base_url) →max_completion_tokensmax_completion_tokens(Groq supports the newer name)base_url, ollama, lmstudio, minimax, volcano →max_tokensA custom
base_urlon theopenaiprovider signals a third-party compatible API (Mistral, Together AI, etc.) that may not have adoptedmax_completion_tokens.Testing
call()argument name, not the API key)call()andcall_with_tools()