From 7a2a158e71f3dc61382932a8120b965eee219051 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Fri, 31 Jul 2026 06:03:36 +0000 Subject: [PATCH] fix(azure): propagate asyncio.CancelledError instead of raising AzureOpenAIError(500) Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- litellm/llms/azure/azure.py | 2 +- tests/test_litellm/llms/azure/test_azure.py | 31 +++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 tests/test_litellm/llms/azure/test_azure.py diff --git a/litellm/llms/azure/azure.py b/litellm/llms/azure/azure.py index ccb9eb8f5c8..bc834e211f2 100644 --- a/litellm/llms/azure/azure.py +++ b/litellm/llms/azure/azure.py @@ -467,7 +467,7 @@ class AzureChatCompletion(BaseAzureLLM, BaseLLM): 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) diff --git a/tests/test_litellm/llms/azure/test_azure.py b/tests/test_litellm/llms/azure/test_azure.py new file mode 100644 index 00000000000..dec4a1dd975 --- /dev/null +++ b/tests/test_litellm/llms/azure/test_azure.py @@ -0,0 +1,31 @@ +import asyncio +import os +import sys + +import pytest +from openai import AsyncAzureOpenAI + +sys.path.insert(0, os.path.abspath("../../../..")) + +import litellm + + +@pytest.mark.asyncio +async def test_acompletion_propagates_cancelled_error(): + client = AsyncAzureOpenAI( + api_key="fake-key", + api_version="2024-02-01", + azure_endpoint="https://fake-resource.openai.azure.com", + ) + + async def cancelled_create(**kwargs): + 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, + )