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(utils.py): support calling openai models via `azure_ai/`
Krrish Dholakia583a3b330d56
diff --git a/litellm/main.py b/litellm/main.pyindex d7a3ca996d3..7be47985745 100644--- a/litellm/main.py+++ b/litellm/main.py@@ -4898,7 +4898,6 @@ async def ahealth_check(verbose_logger.error("litellm.ahealth_check(): Exception occured - {}".format(str(e)))- verbose_logger.debug(traceback.format_exc())stack_trace = traceback.format_exc()if isinstance(stack_trace, str):stack_trace = stack_trace[:1000]@@ -4907,7 +4906,12 @@ async def ahealth_check("error": "Missing `mode`. Set the `mode` for the model - https://docs.litellm.ai/docs/proxy/health#embedding-models"}- error_to_return = str(e) + " stack trace: " + stack_trace+ error_to_return = (+ str(e)+ + "\nHave you set 'mode' - https://docs.litellm.ai/docs/proxy/health#embedding-models"+ + "\nstack trace: "+ + stack_trace+ )return {"error": error_to_return}diff --git a/litellm/proxy/_new_secret_config.yaml b/litellm/proxy/_new_secret_config.yamlindex 87a561e3183..41b2a66c018 100644--- a/litellm/proxy/_new_secret_config.yaml+++ b/litellm/proxy/_new_secret_config.yaml@@ -1,7 +1,7 @@model_list:- - model_name: "*"+ - model_name: azure-embedding-modellitellm_params:- model: "*"--litellm_settings:- success_callback: ["langsmith"]\ No newline at end of file+ model: azure/azure-embedding-model+ api_base: os.environ/AZURE_API_BASE+ api_key: os.environ/AZURE_API_KEY+ api_version: "2023-07-01-preview"diff --git a/litellm/tests/test_completion.py b/litellm/tests/test_completion.pyindex 4ea9ee3b0f3..033b4431fa1 100644--- a/litellm/tests/test_completion.py+++ b/litellm/tests/test_completion.py@@ -190,6 +190,31 @@ def test_completion_azure_command_r():pytest.fail(f"Error occurred: {e}")+ "api_base",+ [+ "https://litellm8397336933.openai.azure.com",+ "https://litellm8397336933.openai.azure.com/openai/deployments/gpt-4o/chat/completions?api-version=2023-03-15-preview",+ ],+)+def test_completion_azure_ai_gpt_4o(api_base):+ try:+ litellm.set_verbose = True++ response = completion(+ model="azure_ai/gpt-4o",+ api_base=api_base,+ api_key=os.getenv("AZURE_AI_OPENAI_KEY"),+ messages=[{"role": "user", "content": "What is the meaning of life?"}],+ )++ print(response)+ except litellm.Timeout as e:+ pass+ except Exception as e:+ pytest.fail(f"Error occurred: {e}")++@pytest.mark.parametrize("sync_mode", [True, False])@pytest.mark.asyncioasync def test_completion_databricks(sync_mode):diff --git a/litellm/utils.py b/litellm/utils.pyindex 49528d0f771..4c5fc6fd48e 100644--- a/litellm/utils.py+++ b/litellm/utils.py@@ -4479,7 +4479,22 @@ def _is_non_openai_azure_model(model: str) -> bool:or f"mistral/{model_name}" in litellm.mistral_chat_models):return True- except:+ except Exception:+ return False+ return False+++def _is_azure_openai_model(model: str) -> bool:+ try:+ if "/" in model:+ model = model.split("/", 1)[1]+ if (+ model in litellm.open_ai_chat_completion_models+ or model in litellm.open_ai_text_completion_models+ or litellm.open_ai_embedding_models+ ):+ return True+ except Exception:return Falsereturn False@@ -4613,6 +4628,9 @@ def get_llm_provider(elif custom_llm_provider == "azure_ai":api_base = api_base or get_secret("AZURE_AI_API_BASE") # type: ignoredynamic_api_key = api_key or get_secret("AZURE_AI_API_KEY")++ if _is_azure_openai_model(model=model):+ custom_llm_provider = "azure"elif custom_llm_provider == "github":api_base = api_base or get_secret("GITHUB_API_BASE") or "https://models.inference.ai.azure.com" # type: ignoredynamic_api_key = api_key or get_secret("GITHUB_API_KEY")