[Bug] OpenAI provider sends max_tokens to gpt-5 and o-series, request fails
Found while testing LLM provider integrations in agent frameworks: an automated tool flags candidates and each one is reproduced before it is reported. Reproduced on 45fc701.
Pre-checks
- [x] I have searched existing issues and this is not a duplicate.
Deployment Method
Source (setup.sh)
Steps to Reproduce
Version 1.11.4-fix.1.
- Add a model with provider OpenAI (or Azure OpenAI) and a reasoning model such as
gpt-5.4-mini,gpt-5.5oro3. - Press the model test, or send an agent a message.
The request can be seen without a key:
from app.services.llm.client import LLMMessage, create_llm_client
client = create_llm_client(provider="openai", model="gpt-5.4-mini", api_key="x")
payload = client._build_payload([LLMMessage(role="user", content="hi")], None, None, 16384)
print({k: v for k, v in payload.items() if "tokens" in k})
# {'max_tokens': 16384}
I also ran RuntimeModelStepService and complete_llm_once against a local fake endpoint that answers max_tokens with OpenAI's 400. No real API was called. Each of those models ended with Model provider rejected the request (HTTP 400). on the first step.
Expected vs Actual Behavior
Expected: these models get max_completion_tokens and the agent answers.
Actual: every request carries max_tokens, because get_max_tokens always returns a value, so the Run fails on its first model call. The API reference says max_tokens "is not compatible with o-series models", and Azure's reasoning page says "Reasoning models will only work with the max_completion_tokens parameter when using the Chat Completions API", GPT-5 models included. The error reported for gpt-5.4 on the OpenAI forum is Unsupported parameter: 'max_tokens' is not supported with this model. Use 'max_completion_tokens' instead.
Choosing the OpenAI Responses provider avoids it, since that client sends max_output_tokens, but nothing in the model form points there.
Logs / Screenshots
Cause: OpenAICompatibleClient._build_payload always writes max_tokens.
Fix idea: for providers openai and azure, send max_completion_tokens when the model name matches ^(o\d|gpt-[5-9]), and keep max_tokens for older models and other providers. The o-series also needs parallel_tool_calls left out, since Azure's table shows no parallel tool calls for it.