From 1e15ff50adef1c44e9eb91628a783e18463451bc Mon Sep 17 00:00:00 2001 From: Soukyu <168991065+ducanhnguyen223@users.noreply.github.com> Date: Fri, 16 Oct 2026 00:23:54 +0700 Subject: [PATCH 1/3] fix(azure-anthropic): strip auth params from body --- .../llms/azure_ai/anthropic/transformation.py | 12 +++--- ...st_azure_ad_token_credential_resolution.py | 40 +++++++++++++++++-- 2 files changed, 43 insertions(+), 9 deletions(-) diff --git a/litellm/llms/azure_ai/anthropic/transformation.py b/litellm/llms/azure_ai/anthropic/transformation.py index 18a4eeb7c0a..0b588b6cc52 100644 --- a/litellm/llms/azure_ai/anthropic/transformation.py +++ b/litellm/llms/azure_ai/anthropic/transformation.py @@ -6,9 +6,14 @@ from typing import Final from litellm.llms.anthropic.chat.transformation import AnthropicConfig from litellm.llms.azure.common_utils import BaseAzureLLM +from litellm.llms.azure_ai.common_utils import AZURE_ENTRA_LITELLM_PARAM_KEYS from litellm.types.llms.openai import AllMessageValues from litellm.types.router import GenericLiteLLMParams +_AZURE_ANTHROPIC_NON_BODY_PARAMS: Final = AZURE_ENTRA_LITELLM_PARAM_KEYS | frozenset( + {"api_key", "azure_ad_token_provider", "extra_body", "max_retries", "stream_options"} +) + def _promote_extra_body_to_optional_params(optional_params: dict) -> None: """Promote anthropic-native passthrough keys out of ``extra_body``. @@ -128,9 +133,4 @@ class AzureAnthropicConfig(AnthropicConfig): headers=headers, ) - # Remove unsupported parameters for Azure AI Anthropic - data.pop("extra_body", None) - data.pop("max_retries", None) - data.pop("stream_options", None) - - return data + return {key: value for key, value in data.items() if key not in _AZURE_ANTHROPIC_NON_BODY_PARAMS} diff --git a/tests/unit/test_azure_ad_token_credential_resolution.py b/tests/unit/test_azure_ad_token_credential_resolution.py index f6f47b3f4c4..07106582d0e 100644 --- a/tests/unit/test_azure_ad_token_credential_resolution.py +++ b/tests/unit/test_azure_ad_token_credential_resolution.py @@ -28,9 +28,7 @@ Tests below pin two things: ``azure_ad_token`` from a deployment's ``litellm_params``. """ -from unittest.mock import MagicMock, patch - -import pytest +from typing import Final class TestCredentialLiteLLMParamsAzureAdToken: @@ -211,3 +209,39 @@ class TestRouterCredentialResolutionS3OutputBucket: assert credentials is not None assert credentials.get("s3_bucket_name") == "in-bucket" assert "s3_output_bucket_name" not in credentials + + +def test_azure_anthropic_request_body_does_not_include_azure_credentials() -> None: + from litellm.llms.azure_ai.anthropic.transformation import AzureAnthropicConfig + + credential_params: Final = { + "api_key": "test-api-key", + "azure_ad_token": "test-access-token", + "azure_ad_token_provider": "test-token-provider", + "client_id": "test-client-id", + "client_secret": "test-client-secret", + "tenant_id": "test-tenant-id", + "azure_scope": "test-scope", + "azure_username": "test-username", + "azure_password": "test-password", + } + output_config: Final = {"format": {"type": "json_object"}} + extra_body_params: Final = { + key: value + for key, value in credential_params.items() + if key not in {"api_key", "azure_ad_token"} + } + body: Final = AzureAnthropicConfig().transform_request( + model="claude-3-5-sonnet-20241022", + messages=[{"role": "user", "content": "hello"}], + optional_params={ + "api_key": credential_params["api_key"], + "azure_ad_token": credential_params["azure_ad_token"], + "extra_body": {**extra_body_params, "output_config": output_config}, + }, + litellm_params={}, + headers={}, + ) + + assert set(credential_params).isdisjoint(body) + assert body["output_config"] == output_config From eb979f7fb37bcd5fc6ba99575993acd76ba48853 Mon Sep 17 00:00:00 2001 From: Soukyu <168991065+ducanhnguyen223@users.noreply.github.com> Date: Fri, 16 Oct 2026 00:35:58 +0700 Subject: [PATCH 2/3] fix(azure-anthropic): type transformed request body --- .../llms/azure_ai/anthropic/transformation.py | 24 ++++++++++--------- ...st_azure_ad_token_credential_resolution.py | 8 +++---- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/litellm/llms/azure_ai/anthropic/transformation.py b/litellm/llms/azure_ai/anthropic/transformation.py index 0b588b6cc52..a25559ecef3 100644 --- a/litellm/llms/azure_ai/anthropic/transformation.py +++ b/litellm/llms/azure_ai/anthropic/transformation.py @@ -115,22 +115,24 @@ class AzureAnthropicConfig(AnthropicConfig): self, model: str, messages: list[AllMessageValues], - optional_params: dict, - litellm_params: dict, - headers: dict, - ) -> dict: + optional_params: dict[str, object], + litellm_params: dict[str, object], + headers: dict[str, object], + ) -> dict[str, object]: """ Transform request using parent AnthropicConfig, then remove unsupported params. Azure Anthropic doesn't support extra_body, max_retries, or stream_options parameters. """ _promote_extra_body_to_optional_params(optional_params) - data: Final = super().transform_request( - model=model, - messages=messages, - optional_params=optional_params, - litellm_params=litellm_params, - headers=headers, - ) + data: Final[dict[str, object]] = { + **super().transform_request( + model=model, + messages=messages, + optional_params=optional_params, + litellm_params=litellm_params, + headers=headers, + ) + } return {key: value for key, value in data.items() if key not in _AZURE_ANTHROPIC_NON_BODY_PARAMS} diff --git a/tests/unit/test_azure_ad_token_credential_resolution.py b/tests/unit/test_azure_ad_token_credential_resolution.py index 07106582d0e..c0469842c0f 100644 --- a/tests/unit/test_azure_ad_token_credential_resolution.py +++ b/tests/unit/test_azure_ad_token_credential_resolution.py @@ -214,7 +214,7 @@ class TestRouterCredentialResolutionS3OutputBucket: def test_azure_anthropic_request_body_does_not_include_azure_credentials() -> None: from litellm.llms.azure_ai.anthropic.transformation import AzureAnthropicConfig - credential_params: Final = { + credential_params: Final[dict[str, str]] = { "api_key": "test-api-key", "azure_ad_token": "test-access-token", "azure_ad_token_provider": "test-token-provider", @@ -225,13 +225,13 @@ def test_azure_anthropic_request_body_does_not_include_azure_credentials() -> No "azure_username": "test-username", "azure_password": "test-password", } - output_config: Final = {"format": {"type": "json_object"}} - extra_body_params: Final = { + output_config: Final[dict[str, dict[str, str]]] = {"format": {"type": "json_object"}} + extra_body_params: Final[dict[str, str]] = { key: value for key, value in credential_params.items() if key not in {"api_key", "azure_ad_token"} } - body: Final = AzureAnthropicConfig().transform_request( + body: Final[dict[str, object]] = AzureAnthropicConfig().transform_request( model="claude-3-5-sonnet-20241022", messages=[{"role": "user", "content": "hello"}], optional_params={ From 54c3710d9f461c7fffe64c711f29191e2bf07082 Mon Sep 17 00:00:00 2001 From: Soukyu <168991065+ducanhnguyen223@users.noreply.github.com> Date: Fri, 16 Oct 2026 00:42:47 +0700 Subject: [PATCH 3/3] fix(azure-anthropic): satisfy type gates --- .../llms/azure_ai/anthropic/transformation.py | 30 ++++++++++--------- ...st_azure_ad_token_credential_resolution.py | 26 +++++----------- 2 files changed, 24 insertions(+), 32 deletions(-) diff --git a/litellm/llms/azure_ai/anthropic/transformation.py b/litellm/llms/azure_ai/anthropic/transformation.py index a25559ecef3..466be954a25 100644 --- a/litellm/llms/azure_ai/anthropic/transformation.py +++ b/litellm/llms/azure_ai/anthropic/transformation.py @@ -115,24 +115,26 @@ class AzureAnthropicConfig(AnthropicConfig): self, model: str, messages: list[AllMessageValues], - optional_params: dict[str, object], - litellm_params: dict[str, object], - headers: dict[str, object], - ) -> dict[str, object]: + optional_params: dict, + litellm_params: dict, + headers: dict, + ) -> dict: """ Transform request using parent AnthropicConfig, then remove unsupported params. Azure Anthropic doesn't support extra_body, max_retries, or stream_options parameters. """ _promote_extra_body_to_optional_params(optional_params) - data: Final[dict[str, object]] = { - **super().transform_request( - model=model, - messages=messages, - optional_params=optional_params, - litellm_params=litellm_params, - headers=headers, - ) - } + data: Final = super().transform_request( + model=model, + messages=messages, + optional_params=optional_params, + litellm_params=litellm_params, + headers=headers, + ) - return {key: value for key, value in data.items() if key not in _AZURE_ANTHROPIC_NON_BODY_PARAMS} + return { + key: value + for key, value in data.items() # pyright: ignore[reportUnknownVariableType] # Anthropic base returns a bare request dict + if key not in _AZURE_ANTHROPIC_NON_BODY_PARAMS + } diff --git a/tests/unit/test_azure_ad_token_credential_resolution.py b/tests/unit/test_azure_ad_token_credential_resolution.py index c0469842c0f..d2901f8adaa 100644 --- a/tests/unit/test_azure_ad_token_credential_resolution.py +++ b/tests/unit/test_azure_ad_token_credential_resolution.py @@ -71,9 +71,9 @@ class TestCredentialLiteLLMParamsAzureAdToken: "azure_ad_token": "tok-123", "api_key": None, # M2M deployment has no static key } - rebuilt = CredentialLiteLLMParams( - **{k: v for k, v in source.items() if v is not None} - ).model_dump(exclude_none=True) + rebuilt = CredentialLiteLLMParams(**{k: v for k, v in source.items() if v is not None}).model_dump( + exclude_none=True + ) assert rebuilt.get("azure_ad_token") == "tok-123" assert rebuilt.get("api_base") == "https://my.openai.azure.com" assert "api_key" not in rebuilt @@ -103,9 +103,7 @@ class TestRouterCredentialResolution: ] ) - credentials = router.get_deployment_credentials_with_provider( - model_id=deployment_id - ) + credentials = router.get_deployment_credentials_with_provider(model_id=deployment_id) assert credentials is not None assert credentials.get("azure_ad_token") == "tok-azure-m2m-xyz", ( "Router credential resolution dropped azure_ad_token; the " @@ -135,9 +133,7 @@ class TestRouterCredentialResolution: ] ) - credentials = router.get_deployment_credentials_with_provider( - model_id=deployment_id - ) + credentials = router.get_deployment_credentials_with_provider(model_id=deployment_id) assert credentials is not None assert credentials.get("api_key") == "sk-static-key" assert "azure_ad_token" not in credentials @@ -172,9 +168,7 @@ class TestRouterCredentialResolutionS3OutputBucket: ] ) - credentials = router.get_deployment_credentials_with_provider( - model_id=deployment_id - ) + credentials = router.get_deployment_credentials_with_provider(model_id=deployment_id) assert credentials is not None assert credentials.get("s3_output_bucket_name") == "out-bucket", ( "Router credential resolution dropped s3_output_bucket_name; " @@ -203,9 +197,7 @@ class TestRouterCredentialResolutionS3OutputBucket: ] ) - credentials = router.get_deployment_credentials_with_provider( - model_id=deployment_id - ) + credentials = router.get_deployment_credentials_with_provider(model_id=deployment_id) assert credentials is not None assert credentials.get("s3_bucket_name") == "in-bucket" assert "s3_output_bucket_name" not in credentials @@ -227,9 +219,7 @@ def test_azure_anthropic_request_body_does_not_include_azure_credentials() -> No } output_config: Final[dict[str, dict[str, str]]] = {"format": {"type": "json_object"}} extra_body_params: Final[dict[str, str]] = { - key: value - for key, value in credential_params.items() - if key not in {"api_key", "azure_ad_token"} + key: value for key, value in credential_params.items() if key not in {"api_key", "azure_ad_token"} } body: Final[dict[str, object]] = AzureAnthropicConfig().transform_request( model="claude-3-5-sonnet-20241022",