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
Merge remote-tracking branch 'origin/litellm_internal_staging' into litellm_lit_7022_azure_ai_passthrough_config
mateo-berri22d7616fe739
diff --cc tests/test_litellm/proxy/pass_through_endpoints/test_llm_pass_through_endpoints.pyindex a2043808b6b,d9969dd1dc9..6ff14157468--- 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@@@ -5208,88 -5208,35 +5208,122 @@@ class TestAzureRouterModelStreamingKeepassert chunks == [b"data: hello\n\n"]+class TestRouterModelRelayUpstreamContract:+ def _request(self, content_type: str) -> MagicMock:+ request = MagicMock(spec=Request)+ request.method = "POST"+ request.headers = {"content-type": content_type}+ request.query_params = {}+ return request++ def _install_router(self, monkeypatch, router, body: dict) -> None:+ import litellm.proxy.pass_through_endpoints.llm_passthrough_endpoints as ep+ import litellm.proxy.proxy_server as proxy_server++ async def fake_get_request_body(_request):+ return body++ monkeypatch.setattr(proxy_server, "llm_router", router)+ monkeypatch.setattr(ep, "get_request_body", fake_get_request_body)+ monkeypatch.setattr(ep, "is_passthrough_request_using_router_model", lambda *a, **k: True)++ def _recording_router(self, captured: list[dict]):+ class RecordingRouter:+ async def allm_passthrough_route(self, **kwargs):+ captured.append(kwargs)+ return httpx.Response(200, json={"ok": True})++ return RecordingRouter()++ @pytest.mark.asyncio+ async def test_azure_relay_keeps_the_json_body_when_the_content_type_carries_a_charset(self, monkeypatch):+ body = {"model": "gpt-5", "messages": [{"role": "user", "content": "hi"}]}+ captured: list[dict] = []+ self._install_router(monkeypatch, self._recording_router(captured), body)++ await azure_proxy_route(+ endpoint="openai/deployments/gpt-5/chat/completions",+ request=self._request("application/json; charset=utf-8"),+ fastapi_response=MagicMock(spec=Response),+ user_api_key_dict=UserAPIKeyAuth(api_key="hashed-token"),+ )++ assert captured[0]["json"] == body++ @pytest.mark.asyncio+ async def test_vllm_relay_keeps_the_json_body_when_the_content_type_carries_a_charset(self, monkeypatch):+ body = {"model": "router-model", "messages": [{"role": "user", "content": "hi"}]}+ captured: list[dict] = []+ self._install_router(monkeypatch, self._recording_router(captured), body)++ await vllm_proxy_route(+ endpoint="/chat/completions",+ request=self._request("application/json; charset=utf-8"),+ fastapi_response=MagicMock(spec=Response),+ user_api_key_dict=UserAPIKeyAuth(api_key="hashed-token"),+ )++ assert captured[0]["json"] == body++ @pytest.mark.asyncio+ async def test_azure_relay_returns_the_upstream_status_and_body_when_the_deployment_rejects_the_call(+ self, monkeypatch+ ):+ upstream_body = {"error": {"code": "DeploymentNotFound", "message": "The API deployment does not exist."}}++ class RejectingRouter:+ async def allm_passthrough_route(self, **kwargs):+ upstream_request = httpx.Request(+ "POST", "https://my-azure.openai.azure.com/openai/deployments/gpt-5/chat/completions"+ )+ upstream = httpx.Response(+ 404, json=upstream_body, headers={"x-ms-request-id": "req-1"}, request=upstream_request+ )+ raise httpx.HTTPStatusError("404", request=upstream_request, response=upstream)++ self._install_router(monkeypatch, RejectingRouter(), {"model": "gpt-5", "stream": False})++ result = await azure_proxy_route(+ endpoint="openai/deployments/gpt-5/chat/completions",+ request=self._request("application/json"),+ fastapi_response=MagicMock(spec=Response),+ user_api_key_dict=UserAPIKeyAuth(api_key="hashed-token"),+ )++ assert result.status_code == 404+ assert json.loads(result.body) == upstream_body+ assert result.headers["x-ms-request-id"] == "req-1"+++++ @pytest.mark.asyncio+ async def test_bedrock_count_tokens_error_forwards_provider_headers():+ """The count tokens route converts BedrockError into an HTTPException, and dropping the+ headers there loses x-amzn-RequestId after the handler went to the trouble of keeping it."""+ from fastapi import HTTPException++ from litellm.llms.bedrock.common_utils import BedrockError+ from litellm.proxy.pass_through_endpoints.llm_passthrough_endpoints import (+ handle_bedrock_count_tokens,+ )++ failure = BedrockError(+ status_code=500,+ message="Amazon Bedrock is unable to process your request.",+ headers={"x-amzn-RequestId": "req-count-tokens-500"},+ )++ with patch( # test-quality-ok: the route's BedrockError branch is only reachable when the handler raises+ "litellm.llms.bedrock.count_tokens.handler.BedrockCountTokensHandler.handle_count_tokens_request",+ new=AsyncMock(side_effect=failure),+ ):+ with pytest.raises(HTTPException) as exc_info:+ await handle_bedrock_count_tokens(+ endpoint="v1/messages/count_tokens",+ request=MagicMock(),+ fastapi_response=MagicMock(),+ user_api_key_dict=MagicMock(),+ request_body={"model": "anthropic.claude-haiku-4-5-20251001-v1:0"},+ )++ assert exc_info.value.status_code == 500+ assert exc_info.value.headers["llm_provider-x-amzn-requestid"] == "req-count-tokens-500"