The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
test_bedrock_error_handling_returns_actual_error
Ishaan Jaffer51f1907e982d
diff --git a/tests/test_litellm/proxy/pass_through_endpoints/test_llm_pass_through_endpoints.py b/tests/test_litellm/proxy/pass_through_endpoints/test_llm_pass_through_endpoints.pyindex 239f83b21ad..38d5c5cdb6d 100644--- a/tests/test_litellm/proxy/pass_through_endpoints/test_llm_pass_through_endpoints.py+++ b/tests/test_litellm/proxy/pass_through_endpoints/test_llm_pass_through_endpoints.py@@ -18,12 +18,12 @@ import litellmfrom litellm.proxy.pass_through_endpoints.llm_passthrough_endpoints import (BaseOpenAIPassThroughHandler,RouteChecks,+ bedrock_llm_proxy_route,create_pass_through_route,llm_passthrough_factory_proxy_route,- vllm_proxy_route,vertex_discovery_proxy_route,vertex_proxy_route,- bedrock_llm_proxy_route,+ vllm_proxy_route,)from litellm.types.passthrough_endpoints.vertex_ai import VertexPassThroughCredentials@@ -996,6 +996,58 @@ class TestBedrockLLMProxyRoute:assert call_kwargs["model"] == "anthropic.claude-3-sonnet-20240229-v1:0"assert result == "success"+ @pytest.mark.asyncio+ async def test_bedrock_error_handling_returns_actual_error(self):+ """+ Test that when Bedrock API returns an error, it is properly propagated to the user+ instead of being returned as a generic "Internal Server Error".+ """+ from fastapi import HTTPException++ from litellm.llms.base_llm.chat.transformation import BaseLLMException+ from litellm.proxy.pass_through_endpoints.llm_passthrough_endpoints import (+ handle_bedrock_passthrough_router_model,+ )++ mock_request = Mock()+ mock_request.method = "POST"+ mock_request.headers = {"content-type": "application/json"}+ mock_request.query_params = {}++ mock_request_body = {+ "messages": [+ {+ "role": "user",+ "content": [{"textaaa": "Hello"}]+ }+ ]+ }++ bedrock_error_message = '{"message":"ContentBlock object at messages.0.content.0 must set one of the following keys: text, image, toolUse, toolResult, document, video."}'++ mock_llm_router = Mock()+ mock_llm_router.allm_passthrough_route = AsyncMock(+ side_effect=BaseLLMException(+ status_code=400,+ message=bedrock_error_message+ )+ )++ endpoint = "model/test-model/converse"+ model = "test-model"++ with pytest.raises(HTTPException) as exc_info:+ await handle_bedrock_passthrough_router_model(+ model=model,+ endpoint=endpoint,+ request=mock_request,+ request_body=mock_request_body,+ llm_router=mock_llm_router,+ )++ assert exc_info.value.status_code == 400+ assert "ContentBlock object at messages.0.content.0 must set one of the following keys" in str(exc_info.value.detail)+class TestLLMPassthroughFactoryProxyRoute:@pytest.mark.asyncio