From e51c91b7ada84d17a522fee594a6407d20b4d9d3 Mon Sep 17 00:00:00 2001 From: Clawdbot Date: Sat, 11 Apr 2026 04:37:56 +0200 Subject: [PATCH 1/2] fix: use max_completion_tokens for Azure OpenAI (#461) Co-Authored-By: Claude --- src/fast_agent/llm/provider/openai/llm_openai.py | 5 ++++- tests/unit/fast_agent/llm/test_prepare_arguments.py | 10 ++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/fast_agent/llm/provider/openai/llm_openai.py b/src/fast_agent/llm/provider/openai/llm_openai.py index 22d6a1df4..d0b596716 100644 --- a/src/fast_agent/llm/provider/openai/llm_openai.py +++ b/src/fast_agent/llm/provider/openai/llm_openai.py @@ -1208,7 +1208,10 @@ def _prepare_api_request( } ) else: - base_args["max_tokens"] = request_params.maxTokens + if self.provider is Provider.AZURE: + base_args["max_completion_tokens"] = request_params.maxTokens + else: + base_args["max_tokens"] = request_params.maxTokens if tools: base_args["parallel_tool_calls"] = request_params.parallel_tool_calls diff --git a/tests/unit/fast_agent/llm/test_prepare_arguments.py b/tests/unit/fast_agent/llm/test_prepare_arguments.py index da9b3b4bd..cb16ccba2 100644 --- a/tests/unit/fast_agent/llm/test_prepare_arguments.py +++ b/tests/unit/fast_agent/llm/test_prepare_arguments.py @@ -159,6 +159,16 @@ def test_openai_provider_arguments(self): assert "max_iterations" not in result # Should be excluded assert "parallel_tool_calls" not in result # Should be excluded + def test_openai_azure_uses_max_completion_tokens(self): + """Azure OpenAI should use max_completion_tokens instead of max_tokens.""" + llm = OpenAILLM(provider=Provider.AZURE) + params = RequestParams(model="gpt-4.1", maxTokens=123) + + result = llm._prepare_api_request(messages=[], tools=None, request_params=params) + + assert result["max_completion_tokens"] == 123 + assert "max_tokens" not in result + def test_anthropic_provider_arguments(self): """Test prepare_provider_arguments with Anthropic provider""" # Create an Anthropic LLM instance without initializing provider connections From c19f90278edf97ecb5c865e2869c9d76cd1c379e Mon Sep 17 00:00:00 2001 From: evalstate <1936278+evalstate@users.noreply.github.com> Date: Mon, 13 Apr 2026 12:07:25 +0100 Subject: [PATCH 2/2] test: strengthen azure max completion tokens coverage --- tests/unit/fast_agent/llm/test_prepare_arguments.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/unit/fast_agent/llm/test_prepare_arguments.py b/tests/unit/fast_agent/llm/test_prepare_arguments.py index cb16ccba2..5c4b4b00a 100644 --- a/tests/unit/fast_agent/llm/test_prepare_arguments.py +++ b/tests/unit/fast_agent/llm/test_prepare_arguments.py @@ -161,9 +161,11 @@ def test_openai_provider_arguments(self): def test_openai_azure_uses_max_completion_tokens(self): """Azure OpenAI should use max_completion_tokens instead of max_tokens.""" - llm = OpenAILLM(provider=Provider.AZURE) + llm = OpenAILLM(provider=Provider.AZURE, request_params=RequestParams(model="gpt-4.1")) params = RequestParams(model="gpt-4.1", maxTokens=123) + assert llm._reasoning is False + result = llm._prepare_api_request(messages=[], tools=None, request_params=params) assert result["max_completion_tokens"] == 123