From b1968a8e3372773123872d534c0faaf92fb9ede7 Mon Sep 17 00:00:00 2001 From: Cesar Garcia <128240629+Chesars@users.noreply.github.com> Date: Tue, 27 Jan 2026 01:47:35 -0300 Subject: [PATCH] fix(responses): update local_vars with detected provider (#19782) (#19798) When using the responses API with provider-specific params (aws_*, vertex_*) without explicitly passing custom_llm_provider, the code crashed with: AttributeError: 'NoneType' object has no attribute 'startswith' Root cause: local_vars was captured via locals() before get_llm_provider() detected the provider from the model string (e.g., "bedrock/..."), so custom_llm_provider remained None when processing provider-specific params. Fix: Update local_vars["custom_llm_provider"] after get_llm_provider() call so the detected provider is available for param processing. Affected provider-specific params: - aws_* (aws_region_name, aws_access_key_id, etc.) for Bedrock/SageMaker - vertex_* (vertex_project, vertex_location, etc.) for Vertex AI --- litellm/responses/main.py | 10 +++++ .../responses/test_responses_utils.py | 43 +++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/litellm/responses/main.py b/litellm/responses/main.py index 83c23a58500..b2c2493c812 100644 --- a/litellm/responses/main.py +++ b/litellm/responses/main.py @@ -434,6 +434,8 @@ async def aresponses( _, custom_llm_provider, _, _ = litellm.get_llm_provider( model=model, api_base=local_vars.get("base_url", None) ) + # Update local_vars with detected provider (fixes #19782) + local_vars["custom_llm_provider"] = custom_llm_provider func = partial( responses, @@ -583,6 +585,9 @@ def responses( api_key=litellm_params.api_key, ) + # Update local_vars with detected provider (fixes #19782) + local_vars["custom_llm_provider"] = custom_llm_provider + # Use dynamic credentials from get_llm_provider (e.g., when use_litellm_proxy=True) if dynamic_api_key is not None: litellm_params.api_key = dynamic_api_key @@ -1411,6 +1416,8 @@ async def acompact_responses( _, custom_llm_provider, _, _ = litellm.get_llm_provider( model=model, api_base=local_vars.get("base_url", None) ) + # Update local_vars with detected provider (fixes #19782) + local_vars["custom_llm_provider"] = custom_llm_provider func = partial( compact_responses, @@ -1498,6 +1505,9 @@ def compact_responses( api_key=litellm_params.api_key, ) + # Update local_vars with detected provider (fixes #19782) + local_vars["custom_llm_provider"] = custom_llm_provider + # Use dynamic credentials from get_llm_provider (e.g., when use_litellm_proxy=True) if dynamic_api_key is not None: litellm_params.api_key = dynamic_api_key diff --git a/tests/test_litellm/responses/test_responses_utils.py b/tests/test_litellm/responses/test_responses_utils.py index 3eb9c63e1be..8f7acb6c120 100644 --- a/tests/test_litellm/responses/test_responses_utils.py +++ b/tests/test_litellm/responses/test_responses_utils.py @@ -309,3 +309,46 @@ class TestResponseAPILoggingUtils: assert result.completion_tokens_details.reasoning_tokens == 30 assert result.completion_tokens_details.image_tokens == 100 assert result.completion_tokens_details.text_tokens == 70 + + +class TestResponsesAPIProviderSpecificParams: + """ + Tests for fix #19782: provider-specific params (aws_*, vertex_*) should work + without explicitly passing custom_llm_provider. + """ + + def test_provider_specific_params_no_crash_with_bedrock(self): + """Test that processing aws_* params with bedrock provider doesn't crash.""" + params = { + "temperature": 0.7, + "custom_llm_provider": "bedrock", + "kwargs": {"aws_region_name": "eu-central-1"}, + } + + # Should not raise any exception + result = ResponsesAPIRequestUtils.get_requested_response_api_optional_param(params) + assert "temperature" in result + + def test_provider_specific_params_no_crash_with_openai(self): + """Test that processing aws_* params with openai provider doesn't crash.""" + params = { + "temperature": 0.7, + "custom_llm_provider": "openai", + "kwargs": {"aws_region_name": "eu-central-1"}, + } + + # Should not raise any exception + result = ResponsesAPIRequestUtils.get_requested_response_api_optional_param(params) + assert "temperature" in result + + def test_provider_specific_params_no_crash_with_vertex_ai(self): + """Test that processing vertex_* params with vertex_ai provider doesn't crash.""" + params = { + "temperature": 0.7, + "custom_llm_provider": "vertex_ai", + "kwargs": {"vertex_project": "my-project"}, + } + + # Should not raise any exception + result = ResponsesAPIRequestUtils.get_requested_response_api_optional_param(params) + assert "temperature" in result