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 remote-tracking branch 'origin/litellm_internal_staging' into litellm_fix_azure_ai_reclassify

mateo-berri6edb72f79c05
diff --cc litellm/constants.py
index 041a83f53e6,ef9329b9dfc..1cffe0b8d8e
--- a/litellm/constants.py
+++ b/litellm/constants.py
@@@ -7,9 -7,40 +7,41 @@@ from litellm.litellm_core_utils.env_uti
DEFAULT_HEALTH_CHECK_PROMPT: Final = str(os.getenv("DEFAULT_HEALTH_CHECK_PROMPT", "test from litellm"))
AZURE_DEFAULT_RESPONSES_API_VERSION: Final = str(os.getenv("AZURE_DEFAULT_RESPONSES_API_VERSION", "preview"))
+AZURE_OPENAI_AUDIO_PROVIDERS: Final = frozenset({"azure", "azure_ai"})
ROUTER_MAX_FALLBACKS: Final = int(os.getenv("ROUTER_MAX_FALLBACKS", 5))
ROUTER_FALLBACK_ERROR_DETAIL_MAX_CHARS: Final = 2000
+ RUNTIME_UPDATABLE_ROUTER_SETTINGS: Final[frozenset[str]] = frozenset(
+ {
+ "routing_strategy_args",
+ "routing_strategy",
+ "routing_groups",
+ "allowed_fails",
+ "cooldown_time",
+ "num_retries",
+ "timeout",
+ "max_retries",
+ "retry_after",
+ "fallbacks",
+ "context_window_fallbacks",
+ "retry_policy",
+ "model_group_retry_policy",
+ "model_group_alias",
+ "enable_weighted_failover",
+ "enable_tag_filtering",
+ "tag_routing_prefix",
+ "optional_pre_call_checks",
+ }
+ )
+ ROUTER_SETTINGS_MANAGED_OUTSIDE_CONFIG: Final[frozenset[str]] = frozenset(
+ {
+ "model_list",
+ "search_tools",
+ "assistants_config",
+ "router_general_settings",
+ "ignore_invalid_deployments",
+ "fallback_access_check",
+ }
+ )
DEFAULT_BATCH_SIZE: Final = int(os.getenv("DEFAULT_BATCH_SIZE", 512))
DEFAULT_FLUSH_INTERVAL_SECONDS: Final = int(os.getenv("DEFAULT_FLUSH_INTERVAL_SECONDS", 5))
DEFAULT_S3_FLUSH_INTERVAL_SECONDS: Final = int(os.getenv("DEFAULT_S3_FLUSH_INTERVAL_SECONDS", 10))
diff --cc tests/test_litellm/test_main.py
index bcb01864a3f,3c8bf142835..857c5e1357b
--- a/tests/test_litellm/test_main.py
+++ b/tests/test_litellm/test_main.py
@@@ -3239,41 -3240,22 +3240,62 @@@ def test_stream_chunk_builder_prices_al
assert response._hidden_params["response_cost"] == pytest.approx(0.000704)
+ def test_stream_chunk_builder_leaves_xai_reported_cost_to_the_calculator(monkeypatch: pytest.MonkeyPatch):
+ monkeypatch.setattr(litellm, "cost_margin_config", {"xai": 0.5})
+ usage_chunk: Final = _stream_builder_text_chunk("grok-4", "")
+ usage_chunk.usage = Usage(prompt_tokens=5, completion_tokens=2, total_tokens=7, cost=0.42)
+ chunks: Final = [
+ _stream_builder_text_chunk("grok-4", "Hello "),
+ _stream_builder_text_chunk("grok-4", "world.", finish_reason="stop"),
+ usage_chunk,
+ ]
+ logging_obj: Final = _stream_builder_logging_obj(model="grok-4", custom_llm_provider="xai")
+
+ response: Final = litellm.stream_chunk_builder(
+ chunks=chunks, messages=[{"role": "user", "content": "hi"}], logging_obj=logging_obj
+ )
+
+ assert response is not None
+ assert getattr(response.usage, "cost", None) == pytest.approx(0.42)
+ assert response._hidden_params.get("response_cost") is None
+ assert logging_obj._response_cost_calculator(result=response) == pytest.approx(0.63)
++
++
+FOUNDRY_HOST: Final = "https://my-project.services.ai.azure.com"
+
+
+def test_azure_ai_transcription_on_a_foundry_host_uses_the_azure_openai_deployment_route(
+ respx_mock: respx.MockRouter,
+):
+ route: Final = respx_mock.post(
+ url__regex=r"https://my-project\.services\.ai\.azure\.com/openai/deployments/whisper-1/audio/transcriptions\?api-version=.+"
+ ).mock(return_value=httpx.Response(200, json={"text": "hello"}))
+
+ response: Final = litellm.transcription(
+ model="azure_ai/whisper-1",
+ file=("tone.wav", b"RIFF\x00\x00\x00\x00WAVE", "audio/wav"),
+ api_base=FOUNDRY_HOST,
+ api_key="fake-key",
+ )
+
+ assert route.called
+ assert response.text == "hello"
+
+
+def test_azure_ai_speech_on_a_foundry_host_uses_the_azure_openai_deployment_route(
+ respx_mock: respx.MockRouter,
+):
+ route: Final = respx_mock.post(
+ url__regex=r"https://my-project\.services\.ai\.azure\.com/openai/deployments/tts-1/audio/speech\?api-version=.+"
+ ).mock(return_value=httpx.Response(200, content=b"mp3-bytes"))
+
+ response: Final = litellm.speech(
+ model="azure_ai/tts-1",
+ input="hello",
+ voice="alloy",
+ api_base=FOUNDRY_HOST,
+ api_key="fake-key",
+ )
+
+ assert route.called
+ assert response.content == b"mp3-bytes"