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
feat(azure/): partially working passthrough flow via router
Krrish Dholakia7a61526b7ba8
diff --git a/litellm/llms/azure/common_utils.py b/litellm/llms/azure/common_utils.pyindex 04448681b63..b88b6985a98 100644--- a/litellm/llms/azure/common_utils.py+++ b/litellm/llms/azure/common_utils.py@@ -693,7 +693,7 @@ class BaseAzureLLM(BaseOpenAILLM):def _get_base_azure_url(api_base: Optional[str],litellm_params: Optional[Union[GenericLiteLLMParams, Dict[str, Any]]],- route: Literal["/openai/responses", "/openai/vector_stores"],+ route: Union[Literal["/openai/responses", "/openai/vector_stores"], str],default_api_version: Optional[Union[str, Literal["latest", "preview"]]] = None,) -> str:"""diff --git a/litellm/llms/azure/passthrough/transformation.py b/litellm/llms/azure/passthrough/transformation.pynew file mode 100644index 00000000000..b6fed6b4470--- /dev/null+++ b/litellm/llms/azure/passthrough/transformation.py@@ -0,0 +1,83 @@+from typing import TYPE_CHECKING, List, Optional, Tuple++import httpx++from litellm.llms.azure.common_utils import BaseAzureLLM+from litellm.llms.base_llm.passthrough.transformation import BasePassthroughConfig+from litellm.secret_managers.main import get_secret_str+from litellm.types.llms.openai import AllMessageValues+from litellm.types.router import GenericLiteLLMParams++if TYPE_CHECKING:+ from httpx import URL+++class AzurePassthroughConfig(BasePassthroughConfig):+ def is_streaming_request(self, endpoint: str, request_data: dict) -> bool:+ return "stream" in request_data++ def get_complete_url(+ self,+ api_base: Optional[str],+ api_key: Optional[str],+ model: str,+ endpoint: str,+ request_query_params: Optional[dict],+ litellm_params: dict,+ ) -> Tuple["URL", str]:+ base_target_url = self.get_api_base(api_base)++ if base_target_url is None:+ raise Exception("Azure api base not found")++ litellm_metadata = litellm_params.get("litellm_metadata") or {}+ model_group = litellm_metadata.get("model_group")+ if model_group and model_group in endpoint:+ endpoint = endpoint.replace(model_group, model)++ complete_url = BaseAzureLLM._get_base_azure_url(+ api_base=base_target_url,+ litellm_params=litellm_params,+ route=endpoint,+ default_api_version=litellm_params.get("api_version"),+ )+ return (+ httpx.URL(complete_url),+ base_target_url,+ )++ def validate_environment(+ self,+ headers: dict,+ model: str,+ messages: List[AllMessageValues],+ optional_params: dict,+ litellm_params: dict,+ api_key: Optional[str] = None,+ api_base: Optional[str] = None,+ ) -> dict:+ return BaseAzureLLM._base_validate_azure_environment(+ headers=headers,+ litellm_params=GenericLiteLLMParams(**litellm_params),+ )++ @staticmethod+ def get_api_base(+ api_base: Optional[str] = None,+ ) -> Optional[str]:+ return api_base or get_secret_str("AZURE_API_BASE")++ @staticmethod+ def get_api_key(+ api_key: Optional[str] = None,+ ) -> Optional[str]:+ return api_key or get_secret_str("AZURE_API_KEY")++ @staticmethod+ def get_base_model(model: str) -> Optional[str]:+ return model++ def get_models(+ self, api_key: Optional[str] = None, api_base: Optional[str] = None+ ) -> List[str]:+ return super().get_models(api_key, api_base)diff --git a/litellm/passthrough/main.py b/litellm/passthrough/main.pyindex f4dc1ef6c84..b4a76822022 100644--- a/litellm/passthrough/main.py+++ b/litellm/passthrough/main.py@@ -242,12 +242,14 @@ def llm_passthrough_route(request_query_params=request_query_params,litellm_params=litellm_params_dict,)-- # need to encode the id of application-inference-profile for bedrock++ # [TODO: Refactor to bedrockpassthroughconfig] need to encode the id of application-inference-profile for bedrockif custom_llm_provider == "bedrock" and "application-inference-profile" in endpoint:- encoded_url_str = CommonUtils.encode_bedrock_runtime_modelid_arn(str(updated_url))+ encoded_url_str = CommonUtils.encode_bedrock_runtime_modelid_arn(+ str(updated_url)+ )updated_url = httpx.URL(encoded_url_str)-+# Add or update query parametersprovider_api_key = provider_config.get_api_key(api_key)diff --git a/litellm/proxy/_new_secret_config.yaml b/litellm/proxy/_new_secret_config.yamlindex 8c929fac8d4..0882a9298aa 100644--- a/litellm/proxy/_new_secret_config.yaml+++ b/litellm/proxy/_new_secret_config.yaml@@ -15,7 +15,12 @@ model_list:model: hosted_vllm/whisper-v3api_base: "https://webhook.site/2f385e05-00aa-402b-86d1-efc9261471a5"api_key: dummy-+ - model_name: azure-hidden-model+ litellm_params:+ model: azure/gpt-4.1+ api_base: os.environ/AZURE_API_BASE_ALT+ api_version: "2023-05-15"+ api_key: os.environ/AZURE_API_KEY_HIDDEN# mcp_servers:# github_mcp:diff --git a/litellm/utils.py b/litellm/utils.pyindex 3c6c3ac86e4..7c712b90284 100644--- a/litellm/utils.py+++ b/litellm/utils.py@@ -532,9 +532,6 @@ def get_dynamic_callbacks(return returned_callbacks---def function_setup( # noqa: PLR0915original_function: str, rules_obj, start_time, *args, **kwargs): # just run once to check if user wants to send their data anywhere - PostHog/Sentry/Slack/etc.@@ -802,7 +799,7 @@ def function_setup( # noqa: PLR0915call_type=call_type,):stream = True- logging_obj = get_litellm_logging_class()( # Victim for object pool+ logging_obj = get_litellm_logging_class()( # Victim for object poolmodel=model, # type: ignoremessages=messages,stream=stream,@@ -1417,7 +1414,8 @@ def client(original_function): # noqa: PLR0915if _caching_handler_response is not None:if (_caching_handler_response.cached_result is not None- and _caching_handler_response.final_embedding_cached_response is None+ and _caching_handler_response.final_embedding_cached_response+ is None):return _caching_handler_response.cached_result@@ -1683,7 +1681,6 @@ def _is_streaming_request(return False-def _select_tokenizer(model: str, custom_tokenizer: Optional[CustomHuggingfaceTokenizer] = None):@@ -4867,16 +4864,24 @@ def _get_model_info_helper( # noqa: PLR0915max_input_tokens=_model_info.get("max_input_tokens", None),max_output_tokens=_model_info.get("max_output_tokens", None),input_cost_per_token=_input_cost_per_token,- input_cost_per_token_flex=_model_info.get("input_cost_per_token_flex", None),- input_cost_per_token_priority=_model_info.get("input_cost_per_token_priority", None),+ input_cost_per_token_flex=_model_info.get(+ "input_cost_per_token_flex", None+ ),+ input_cost_per_token_priority=_model_info.get(+ "input_cost_per_token_priority", None+ ),cache_creation_input_token_cost=_model_info.get("cache_creation_input_token_cost", None),cache_read_input_token_cost=_model_info.get("cache_read_input_token_cost", None),- cache_read_input_token_cost_flex=_model_info.get("cache_read_input_token_cost_flex", None),- cache_read_input_token_cost_priority=_model_info.get("cache_read_input_token_cost_priority", None),+ cache_read_input_token_cost_flex=_model_info.get(+ "cache_read_input_token_cost_flex", None+ ),+ cache_read_input_token_cost_priority=_model_info.get(+ "cache_read_input_token_cost_priority", None+ ),cache_creation_input_token_cost_above_1hr=_model_info.get("cache_creation_input_token_cost_above_1hr", None),@@ -4901,8 +4906,12 @@ def _get_model_info_helper( # noqa: PLR0915"output_cost_per_token_batches"),output_cost_per_token=_output_cost_per_token,- output_cost_per_token_flex=_model_info.get("output_cost_per_token_flex", None),- output_cost_per_token_priority=_model_info.get("output_cost_per_token_priority", None),+ output_cost_per_token_flex=_model_info.get(+ "output_cost_per_token_flex", None+ ),+ output_cost_per_token_priority=_model_info.get(+ "output_cost_per_token_priority", None+ ),output_cost_per_audio_token=_model_info.get("output_cost_per_audio_token", None),@@ -6434,7 +6443,7 @@ def get_valid_models(try:################################- # init litellm_params+ # init litellm_params#################################if litellm_params is None:litellm_params = LiteLLM_Params(model="")@@ -6443,7 +6452,7 @@ def get_valid_models(if api_base is not None:litellm_params.api_base = api_base#################################-+check_provider_endpoint = (check_provider_endpoint or litellm.check_provider_endpoint)@@ -6918,7 +6927,10 @@ class ProviderConfigManager:return litellm.LlamaAPIConfig()elif litellm.LlmProviders.TEXT_COMPLETION_OPENAI == provider:return litellm.OpenAITextCompletionConfig()- elif litellm.LlmProviders.COHERE_CHAT == provider or litellm.LlmProviders.COHERE == provider:+ elif (+ litellm.LlmProviders.COHERE_CHAT == provider+ or litellm.LlmProviders.COHERE == provider+ ):return litellm.CohereChatConfig()elif litellm.LlmProviders.SNOWFLAKE == provider:return litellm.SnowflakeConfig()@@ -7345,7 +7357,12 @@ class ProviderConfigManager:)return VLLMPassthroughConfig()+ elif LlmProviders.AZURE == provider:+ from litellm.llms.azure.passthrough.transformation import (+ AzurePassthroughConfig,+ )+ return AzurePassthroughConfig()return None@staticmethod@@ -7532,9 +7549,7 @@ class ProviderConfigManager:return RecraftImageEditConfig()elif LlmProviders.AZURE_AI == provider:- from litellm.llms.azure_ai.image_edit import (- get_azure_ai_image_edit_config,- )+ from litellm.llms.azure_ai.image_edit import get_azure_ai_image_edit_configreturn get_azure_ai_image_edit_config(model)elif LlmProviders.LITELLM_PROXY == provider:@@ -7589,7 +7604,9 @@ def get_end_user_id_for_cost_tracking(service_type: "litellm_logging" or "prometheus" - used to allow prometheus only disable cost tracking."""- _metadata = cast(dict, get_litellm_metadata_from_kwargs(dict(litellm_params=litellm_params)))+ _metadata = cast(+ dict, get_litellm_metadata_from_kwargs(dict(litellm_params=litellm_params))+ )end_user_id = cast(Optional[str],