Skip to content

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]

Merge origin/main into devin_ai_fix_azure_cancellederror_35329

Devin AIb090f765d5a2
diff --cc litellm/llms/azure/azure.py
index bc834e211f2,449319c1b95..2e7e7bb0c9d
--- a/litellm/llms/azure/azure.py
+++ b/litellm/llms/azure/azure.py
@@@ -467,10 -481,10 +481,10 @@@ class AzureChatCompletion(BaseAzureLLM
additional_args={"complete_input_dict": data},
original_response=str(e),
)
- raise AzureOpenAIError(status_code=500, message=str(e))
+ raise
except Exception as e:
- message = getattr(e, "message", str(e))
- body = getattr(e, "body", None)
+ message: Final = getattr(e, "message", str(e))
+ body: Final = getattr(e, "body", None)
## LOGGING
logging_obj.post_call(
input=data["messages"],
diff --cc tests/test_litellm/llms/azure/test_azure.py
index dec4a1dd975,6b6832f623c..b466061c9d1
--- a/tests/test_litellm/llms/azure/test_azure.py
+++ b/tests/test_litellm/llms/azure/test_azure.py
@@@ -1,31 -1,54 +1,78 @@@
+ """Tests for litellm/llms/azure/azure.py AzureChatCompletion handler behaviour."""
+
+import asyncio
- import os
- import sys
+ import time
+ from typing import Final
-from openai import AzureOpenAI
+import pytest
- from openai import AsyncAzureOpenAI
-
- sys.path.insert(0, os.path.abspath("../../../.."))
++from openai import AsyncAzureOpenAI, AzureOpenAI
+import litellm
+ from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObj
+ from litellm.llms.azure.azure import AzureChatCompletion
+
+
+ class _FakeRawResponse:
+ headers: Final = {"x-ms-is-spilled-over": "true"}
+
+ def parse(self):
+ return iter(())
+
+
+ class _FakeRawCompletions:
+ def create(self, **kwargs):
+ return _FakeRawResponse()
+
+
+ def test_sync_streaming_stamps_response_headers_on_the_logging_obj() -> None:
+ """Sync streaming must mirror async_streaming and record the provider response
+ headers on model_call_details, or downstream consumers (spillover-aware cost
+ calculation) cannot see them."""
+ client = AzureOpenAI(api_key="fake", api_version="2024-02-01", azure_endpoint="https://fake.openai.azure.com")
+ client.chat.completions.with_raw_response = _FakeRawCompletions()
+
+ logging_obj = LiteLLMLoggingObj(
+ model="azure/gpt-4o-spill-test",
+ messages=[{"role": "user", "content": "Hi"}],
+ stream=True,
+ call_type="completion",
+ start_time=time.time(),
+ litellm_call_id="spill-sync-1",
+ function_id="f",
+ )
+
+ AzureChatCompletion().streaming(
+ logging_obj=logging_obj,
+ api_base="https://fake.openai.azure.com",
+ api_key="fake",
+ api_version="2024-02-01",
+ dynamic_params=False,
+ data={"messages": [{"role": "user", "content": "Hi"}], "stream": True},
+ model="gpt-4o-spill-test",
+ timeout=30.0,
+ max_retries=0,
+ client=client,
+ )
+
+ assert logging_obj.model_call_details["response_headers"] == {"x-ms-is-spilled-over": "true"}
+
+
- async def test_acompletion_propagates_cancelled_error():
++async def test_acompletion_propagates_cancelled_error() -> None:
+ client = AsyncAzureOpenAI(
+ api_key="fake-key",
+ api_version="2024-02-01",
+ azure_endpoint="https://fake-resource.openai.azure.com",
+ )
+
- async def cancelled_create(**kwargs):
++ async def cancelled_create(**kwargs: object) -> None:
+ raise asyncio.CancelledError()
+
+ client.chat.completions.with_raw_response.create = cancelled_create
+
+ with pytest.raises(asyncio.CancelledError):
+ await litellm.acompletion(
+ model="azure/fake-deployment",
+ messages=[{"role": "user", "content": "hi"}],
+ client=client,
+ )