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(utils.py): accept 'api_version' as param for validate_environment
Qingchuan Haof2a6be390b7c
diff --git a/litellm/utils.py b/litellm/utils.pyindex 05055b7df8b..f5b6a256fa2 100644--- a/litellm/utils.py+++ b/litellm/utils.py@@ -5207,6 +5207,7 @@ def validate_environment( # noqa: PLR0915model: Optional[str] = None,api_key: Optional[str] = None,api_base: Optional[str] = None,+ api_version: Optional[str] = None,) -> dict:"""Checks if the environment variables are valid for the given model.@@ -5552,19 +5553,18 @@ def validate_environment( # noqa: PLR0915else:missing_keys.append("NEBIUS_API_KEY")+ def filter_missing_keys(keys: List[str], exclude_pattern: str) -> List[str]:+ """Filter out keys that contain the exclude_pattern (case insensitive)."""+ return [key for key in keys if exclude_pattern not in key.lower()]+if api_key is not None:- new_missing_keys = []- for key in missing_keys:- if "api_key" not in key.lower():- new_missing_keys.append(key)- missing_keys = new_missing_keys+ missing_keys = filter_missing_keys(missing_keys, "api_key")if api_base is not None:- new_missing_keys = []- for key in missing_keys:- if "api_base" not in key.lower():- new_missing_keys.append(key)- missing_keys = new_missing_keys+ missing_keys = filter_missing_keys(missing_keys, "api_base")++ if api_version is not None:+ missing_keys = filter_missing_keys(missing_keys, "api_version")if len(missing_keys) == 0: # no missing keyskeys_in_environment = Truediff --git a/tests/litellm_utils_tests/test_utils.py b/tests/litellm_utils_tests/test_utils.pyindex e9bfa643f3b..76a180dfa92 100644--- a/tests/litellm_utils_tests/test_utils.py+++ b/tests/litellm_utils_tests/test_utils.py@@ -411,6 +411,13 @@ def test_validate_environment_api_key():), f"Missing keys={response_obj['missing_keys']}"+def test_validate_environment_api_version():+ response_obj = validate_environment(model="azure/openai-deployment", api_key="sk-my-test-key", api_base="https://fake.openai.azure.com/", api_version="2024-02-15")+ assert (+ response_obj["keys_in_environment"] is True+ ), f"Missing keys={response_obj['missing_keys']}"++def test_validate_environment_api_base_dynamic():for provider in ["ollama", "ollama_chat"]:kv = validate_environment(provider + "/mistral", api_base="https://example.com")