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
fix(azure_ai/anthropic): promote output_config out of extra_body so validation runs
mateo-berri4f9a3a5c9f90
diff --git a/litellm/llms/azure_ai/anthropic/transformation.py b/litellm/llms/azure_ai/anthropic/transformation.pyindex e935aa1c057..f3bd6012ec5 100644--- a/litellm/llms/azure_ai/anthropic/transformation.py+++ b/litellm/llms/azure_ai/anthropic/transformation.py@@ -12,6 +12,33 @@ if TYPE_CHECKING:pass+def _promote_extra_body_to_optional_params(optional_params: dict) -> None:+ """Promote anthropic-native passthrough keys out of ``extra_body``.++ ``azure_ai`` is registered in ``litellm.openai_compatible_providers``, so+ ``add_provider_specific_params_to_optional_params`` (litellm/utils.py)+ auto-stuffs any non-OpenAI kwarg (e.g. ``output_config={"effort": "..."}``)+ into ``optional_params["extra_body"]``. For the Azure→Anthropic route the+ user's intent is to forward those params to Anthropic, so promote them to+ the top level of ``optional_params`` so:++ * ``AnthropicConfig._apply_output_config`` validates ``effort`` values+ (matching the native ``anthropic`` provider's 400 on bad efforts).+ * Valid passthroughs (e.g. ``output_config``, ``thinking``) actually+ reach the request body instead of being silently dropped by the+ ``data.pop("extra_body", None)`` strip below.++ ``setdefault`` is used so an explicit top-level value is never clobbered+ by a duplicate inside ``extra_body``.+ """+ extra_body = optional_params.get("extra_body")+ if not isinstance(extra_body, dict) or not extra_body:+ return+ for k, v in extra_body.items():+ optional_params.setdefault(k, v)+ optional_params.pop("extra_body", None)++class AzureAnthropicConfig(AnthropicConfig):"""Azure Anthropic configuration that extends AnthropicConfig.@@ -39,6 +66,11 @@ class AzureAnthropicConfig(AnthropicConfig):1. API key via 'api-key' header2. Azure AD token via 'Authorization: Bearer <token>' header"""+ # Promote anthropic-native passthrough keys (``output_config``,+ # ``thinking``, ``mcp_servers``, ...) out of ``extra_body`` so the+ # flag detection below (``is_mcp_server_used``, etc.) sees them.+ _promote_extra_body_to_optional_params(optional_params)+# Convert dict to GenericLiteLLMParams if neededif isinstance(litellm_params, dict):# Ensure api_key is included if provided@@ -101,6 +133,17 @@ class AzureAnthropicConfig(AnthropicConfig):Transform request using parent AnthropicConfig, then remove unsupported params.Azure Anthropic doesn't support extra_body, max_retries, or stream_options parameters."""+ # Promote anthropic-native passthrough keys (``output_config``,+ # ``thinking``, ...) out of ``extra_body`` BEFORE delegating to+ # ``AnthropicConfig.transform_request``. Without this:+ # * ``output_config`` is silently dropped by the ``extra_body`` pop+ # below, and+ # * ``_apply_output_config`` never validates ``effort`` values, so+ # ``effort="invalid"`` quietly reaches the model with default+ # behavior instead of returning a clean 400 (as the native+ # ``anthropic`` provider does).+ _promote_extra_body_to_optional_params(optional_params)+# Call parent transform_requestdata = super().transform_request(model=model,diff --git a/tests/test_litellm/llms/azure_ai/claude/test_azure_anthropic_transformation.py b/tests/test_litellm/llms/azure_ai/claude/test_azure_anthropic_transformation.pyindex 06ef04ca2ce..2504e9d5b89 100644--- a/tests/test_litellm/llms/azure_ai/claude/test_azure_anthropic_transformation.py+++ b/tests/test_litellm/llms/azure_ai/claude/test_azure_anthropic_transformation.py@@ -291,6 +291,122 @@ class TestAzureAnthropicConfig:assert "anthropic-beta" in headersassert "compact-2026-01-12" in headers["anthropic-beta"]+ def test_output_config_promoted_from_extra_body(self):+ """Anthropic-native ``output_config`` routed via ``extra_body`` (by the+ openai-compatible kwarg stuffer in ``litellm/utils.py``) must be+ promoted to top-level ``optional_params`` before delegating to+ ``AnthropicConfig.transform_request``. Otherwise the value is+ silently dropped by the ``extra_body`` pop and validation never+ runs.+ """+ config = AzureAnthropicConfig()++ messages = [{"role": "user", "content": "Hello"}]+ # Simulate what ``add_provider_specific_params_to_optional_params``+ # produces for ``litellm.completion(model="azure_ai/claude-...",+ # output_config={"effort": "low"})``.+ optional_params = {+ "max_tokens": 100,+ "extra_body": {"output_config": {"effort": "low"}},+ }+ litellm_params = {"api_key": "test-key"}+ headers = {"api-key": "test-key", "anthropic-version": "2023-06-01"}++ result = config.transform_request(+ model="claude-opus-4-6", # supports output_config.effort+ messages=messages,+ optional_params=optional_params,+ litellm_params=litellm_params,+ headers=headers,+ )++ # output_config must reach the request body (not be silently dropped)+ assert "output_config" in result+ assert result["output_config"] == {"effort": "low"}+ # extra_body should be stripped on the way out+ assert "extra_body" not in result++ def test_invalid_output_config_effort_raises_via_extra_body(self):+ """``effort="invalid"`` arriving via ``extra_body`` must still raise+ ``BadRequestError`` (matching the native ``anthropic`` provider).+ Previously this was silently dropped on Azure, so unsupported+ efforts reached the model with default behavior instead of+ returning a clean 400.+ """+ import litellm++ config = AzureAnthropicConfig()++ messages = [{"role": "user", "content": "Hello"}]+ optional_params = {+ "max_tokens": 100,+ "extra_body": {"output_config": {"effort": "invalid"}},+ }+ litellm_params = {"api_key": "test-key"}+ headers = {"api-key": "test-key", "anthropic-version": "2023-06-01"}++ with pytest.raises(litellm.exceptions.BadRequestError) as exc_info:+ config.transform_request(+ model="claude-opus-4-6",+ messages=messages,+ optional_params=optional_params,+ litellm_params=litellm_params,+ headers=headers,+ )+ assert "Invalid effort value" in str(exc_info.value)++ def test_unsupported_effort_xhigh_raises_via_extra_body(self):+ """``effort="xhigh"`` on a model that does not support it (e.g.+ Sonnet 4.6) must raise ``BadRequestError`` even when arriving via+ ``extra_body`` on Azure."""+ import litellm++ config = AzureAnthropicConfig()++ messages = [{"role": "user", "content": "Hello"}]+ optional_params = {+ "max_tokens": 100,+ "extra_body": {"output_config": {"effort": "xhigh"}},+ }+ litellm_params = {"api_key": "test-key"}+ headers = {"api-key": "test-key", "anthropic-version": "2023-06-01"}++ with pytest.raises(litellm.exceptions.BadRequestError) as exc_info:+ config.transform_request(+ model="claude-sonnet-4-6",+ messages=messages,+ optional_params=optional_params,+ litellm_params=litellm_params,+ headers=headers,+ )+ assert "xhigh" in str(exc_info.value)++ def test_extra_body_promotion_does_not_clobber_top_level(self):+ """If a key exists at both top-level ``optional_params`` and+ inside ``extra_body``, the top-level value wins (``setdefault``+ semantics). This protects against a caller who explicitly sets a+ param at top-level and accidentally also has it in extra_body."""+ config = AzureAnthropicConfig()++ messages = [{"role": "user", "content": "Hello"}]+ optional_params = {+ "max_tokens": 100,+ "output_config": {"effort": "low"}, # top-level wins+ "extra_body": {"output_config": {"effort": "high"}}, # ignored+ }+ litellm_params = {"api_key": "test-key"}+ headers = {"api-key": "test-key", "anthropic-version": "2023-06-01"}++ result = config.transform_request(+ model="claude-opus-4-6",+ messages=messages,+ optional_params=optional_params,+ litellm_params=litellm_params,+ headers=headers,+ )++ assert result["output_config"] == {"effort": "low"}+def test_context_management_mixed_edits_beta_headers(self):"""Test that context_management with both compact and other edits adds both beta headers"""config = AzureAnthropicConfig()