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(e2e): add Azure AI Foundry and Anthropic /v1/messages coverage for the Rust bridge (#34021)
Yassin Kortambc374fcd9f0d
diff --git a/tests/e2e/llm_translation/test_messages_azure_foundry_e2e.py b/tests/e2e/llm_translation/test_messages_azure_foundry_e2e.pynew file mode 100644index 00000000000..3f2907f202e--- /dev/null+++ b/tests/e2e/llm_translation/test_messages_azure_foundry_e2e.py@@ -0,0 +1,155 @@+"""Live e2e: POST /v1/messages routed to Azure AI Foundry Anthropic deployments.++Registers `azure_ai/<claude>` deployments at runtime and drives the Messages+endpoint through the gateway across the behaviors an Anthropic client relies on:+a basic completion, a streamed completion, and tool use (non-streaming and+streaming). Auth is the Azure API key (`x-api-key`); the deployment reads+`AZURE_AI_API_BASE` / `AZURE_AI_API_KEY` from the proxy env, so no secret is+sent in the request.+"""++from __future__ import annotations++import pytest++from e2e_config import unique_marker+from e2e_http import StreamingResponse, require_successful_call, unwrap+from endpoints_client import EndpointsClient+from lifecycle import ResourceManager+from models import (+ AnthropicCustomTool,+ AnthropicMessagesBody,+ ChatMessage,+ JsonSchemaProperty,+ LiteLLMParamsBody,+ ToolInputSchema,+)++pytestmark = pytest.mark.e2e++AZURE_FOUNDRY_MODEL = "azure_ai/claude-haiku-4-5"++WEATHER_TOOL = AnthropicCustomTool(+ name="get_weather",+ description="Get the current weather for a city.",+ input_schema=ToolInputSchema(+ properties={"city": JsonSchemaProperty(type="string")},+ required=["city"],+ ),+)+++def _assert_streamed_ok(result: StreamingResponse) -> None:+ require_successful_call(result)+ assert result.is_streaming, f"response was not streamed: {result.headers}"+ assert not result.stream_error, f"stream errored: {result.stream_error}"+ assert result.stream_events, "stream produced no SSE events"+ assert any("content_block_delta" in event for event in result.stream_events), (+ "stream carried no content deltas"+ )+ assert any("message_stop" in event for event in result.stream_events), (+ "stream never reached message_stop"+ )+++class TestAzureFoundryMessages:+ def _register(+ self, endpoints_client: EndpointsClient, resources: ResourceManager+ ) -> tuple[str, str]:+ model = f"e2e-azure-foundry-messages-{unique_marker()}"+ model_id = endpoints_client.create_model(+ model,+ LiteLLMParamsBody(+ model=AZURE_FOUNDRY_MODEL,+ api_base="os.environ/AZURE_AI_API_BASE",+ api_key="os.environ/AZURE_AI_API_KEY",+ ),+ )+ resources.defer(lambda: endpoints_client.delete_model(model_id))+ return model, resources.key(models=[model])++ @pytest.mark.covers("llm.messages.azure_foundry.basic.nonstream.works")+ def test_basic_nonstream(+ self, endpoints_client: EndpointsClient, resources: ResourceManager+ ) -> None:+ model, key = self._register(endpoints_client, resources)+ response = unwrap(+ endpoints_client.proxy.messages(+ key,+ AnthropicMessagesBody(+ model=model,+ max_tokens=64,+ messages=[ChatMessage(role="user", content="Reply with one word.")],+ ),+ )+ )+ assert response.content, f"no content blocks in response: {response}"+ text = "".join(block.text or "" for block in response.content if block.type == "text")+ assert text.strip(), f"/v1/messages returned no text: {response}"++ @pytest.mark.covers("llm.messages.azure_foundry.basic.stream.works")+ def test_basic_stream(+ self, endpoints_client: EndpointsClient, resources: ResourceManager+ ) -> None:+ model, key = self._register(endpoints_client, resources)+ result = endpoints_client.proxy.messages_stream(+ key,+ AnthropicMessagesBody(+ model=model,+ max_tokens=64,+ stream=True,+ messages=[ChatMessage(role="user", content="Count from one to three.")],+ ),+ )+ _assert_streamed_ok(result)++ @pytest.mark.covers("llm.messages.azure_foundry.tool_use.nonstream.works")+ def test_tool_use_nonstream(+ self, endpoints_client: EndpointsClient, resources: ResourceManager+ ) -> None:+ model, key = self._register(endpoints_client, resources)+ response = unwrap(+ endpoints_client.proxy.messages(+ key,+ AnthropicMessagesBody(+ model=model,+ max_tokens=256,+ tools=[WEATHER_TOOL],+ messages=[+ ChatMessage(role="user", content="What is the weather in Paris? Use the tool.")+ ],+ ),+ )+ )+ assert response.content, f"no content blocks in response: {response}"+ assert any(block.type == "tool_use" for block in response.content), (+ f"model did not call the tool: {response}"+ )++ @pytest.mark.covers("llm.messages.azure_foundry.tool_use.stream.works")+ def test_tool_use_stream(+ self, endpoints_client: EndpointsClient, resources: ResourceManager+ ) -> None:+ model, key = self._register(endpoints_client, resources)+ result = endpoints_client.proxy.messages_stream(+ key,+ AnthropicMessagesBody(+ model=model,+ max_tokens=256,+ stream=True,+ tools=[WEATHER_TOOL],+ messages=[+ ChatMessage(role="user", content="What is the weather in Paris? Use the tool.")+ ],+ ),+ )+ require_successful_call(result)+ assert result.is_streaming, f"response was not streamed: {result.headers}"+ assert not result.stream_error, f"stream errored: {result.stream_error}"+ assert result.stream_events, "stream produced no SSE events"+ assert any("tool_use" in event for event in result.stream_events), (+ "stream carried no tool_use block"+ )+ assert any("message_stop" in event for event in result.stream_events), (+ "stream never reached message_stop"+ )diff --git a/tests/e2e/llm_translation/test_messages_e2e.py b/tests/e2e/llm_translation/test_messages_e2e.pyindex b0a48f22118..a14bf8e82b3 100644--- a/tests/e2e/llm_translation/test_messages_e2e.py+++ b/tests/e2e/llm_translation/test_messages_e2e.py@@ -1,7 +1,8 @@"""Live e2e: POST /v1/messages (Anthropic Messages API) returns a real completion.Registers an Anthropic deployment at runtime, drives the Messages endpoint through-the gateway, and asserts an assistant message with text came back. Migrated from+the gateway, and asserts an assistant message with text came back, both+non-streaming and streamed. Migrated fromlitellm-regression-tests/tests/test_inference_endpoints.py."""@@ -10,18 +11,34 @@ from __future__ import annotationsimport pytestfrom e2e_config import unique_marker-from e2e_http import require_successful_call+from e2e_http import require_successful_call, unwrapfrom endpoints_client import EndpointsClient, MessagesResultfrom lifecycle import ResourceManager-from models import LiteLLMParamsBody+from models import (+ AnthropicCustomTool,+ AnthropicMessagesBody,+ ChatMessage,+ JsonSchemaProperty,+ LiteLLMParamsBody,+ ToolInputSchema,+)pytestmark = pytest.mark.e2e+WEATHER_TOOL = AnthropicCustomTool(+ name="get_weather",+ description="Get the current weather for a city.",+ input_schema=ToolInputSchema(+ properties={"city": JsonSchemaProperty(type="string")},+ required=["city"],+ ),+)+class TestAnthropicMessages:- def test_messages_returns_completion(+ def _register(self, endpoints_client: EndpointsClient, resources: ResourceManager- ) -> None:+ ) -> tuple[str, str]:model = f"e2e-messages-{unique_marker()}"model_id = endpoints_client.create_model(model,@@ -30,10 +47,66 @@ class TestAnthropicMessages:),)resources.defer(lambda: endpoints_client.delete_model(model_id))- key = resources.key()+ return model, resources.key()++ @pytest.mark.covers("llm.messages.anthropic.basic.nonstream.works")+ def test_messages_returns_completion(+ self, endpoints_client: EndpointsClient, resources: ResourceManager+ ) -> None:+ model, key = self._register(endpoints_client, resources)result = endpoints_client.messages(key, model, "reply with one word")require_successful_call(result)parsed = MessagesResult.model_validate_json(result.body)assert parsed.role == "assistant", f"unexpected role: {result.body[:300]}"assert parsed.text.strip(), f"/v1/messages returned no text: {result.body[:300]}"++ @pytest.mark.covers("llm.messages.anthropic.basic.stream.works")+ def test_messages_streams_completion(+ self, endpoints_client: EndpointsClient, resources: ResourceManager+ ) -> None:+ model, key = self._register(endpoints_client, resources)++ result = endpoints_client.proxy.messages_stream(+ key,+ AnthropicMessagesBody(+ model=model,+ max_tokens=64,+ stream=True,+ messages=[ChatMessage(role="user", content="Count from one to three.")],+ ),+ )+ require_successful_call(result)+ assert result.is_streaming, f"response was not streamed: {result.headers}"+ assert not result.stream_error, f"stream errored: {result.stream_error}"+ assert result.stream_events, "stream produced no SSE events"+ assert any("content_block_delta" in event for event in result.stream_events), (+ "stream carried no content deltas"+ )+ assert any("message_stop" in event for event in result.stream_events), (+ "stream never reached message_stop"+ )++ @pytest.mark.covers("llm.messages.anthropic.tool_use.nonstream.works")+ def test_messages_tool_use(+ self, endpoints_client: EndpointsClient, resources: ResourceManager+ ) -> None:+ model, key = self._register(endpoints_client, resources)++ response = unwrap(+ endpoints_client.proxy.messages(+ key,+ AnthropicMessagesBody(+ model=model,+ max_tokens=256,+ tools=[WEATHER_TOOL],+ messages=[+ ChatMessage(role="user", content="What is the weather in Paris? Use the tool.")+ ],+ ),+ )+ )+ assert response.content, f"no content blocks in response: {response}"+ assert any(block.type == "tool_use" for block in response.content), (+ f"model did not call the tool: {response}"+ )diff --git a/tests/e2e/models.py b/tests/e2e/models.pyindex 37438010c3b..8b6c454fa1e 100644--- a/tests/e2e/models.py+++ b/tests/e2e/models.py@@ -286,6 +286,7 @@ class CountTokensBody(BaseModel):class AnthropicContentBlock(BaseModel):type: str | None = None+ text: str | None = Noneclass AnthropicMessagesResponse(BaseModel):