diff --git a/litellm/utils.py b/litellm/utils.py index 18b89ee0d13..62eaaf266ec 100644 --- a/litellm/utils.py +++ b/litellm/utils.py @@ -6139,6 +6139,11 @@ def validate_environment( keys_in_environment = True else: missing_keys.append("MOONSHOT_API_KEY") + elif custom_llm_provider == "zai": + if "ZAI_API_KEY" in os.environ: + keys_in_environment = True + else: + missing_keys.append("ZAI_API_KEY") else: ## openai - chatcompletion + text completion if ( diff --git a/tests/test_litellm/test_utils.py b/tests/test_litellm/test_utils.py index 26ae6ff7f4c..426696287d3 100644 --- a/tests/test_litellm/test_utils.py +++ b/tests/test_litellm/test_utils.py @@ -4710,3 +4710,21 @@ class TestValidateEnvironmentTencent: assert "TENCENT_API_KEY" in result["missing_keys"] +class TestValidateEnvironmentZai: + """Tests that validate_environment resolves ZAI_API_KEY for the zai provider.""" + + def test_reports_key_present(self): + with patch.dict(os.environ, {"ZAI_API_KEY": "sk-zai"}): + result = litellm.validate_environment(model="zai/glm-5.1") + + assert result["keys_in_environment"] is True + assert result["missing_keys"] == [] + + def test_reports_key_missing(self): + with patch.dict(os.environ, {}, clear=True): + result = litellm.validate_environment(model="zai/glm-5.1") + + assert result["keys_in_environment"] is False + assert "ZAI_API_KEY" in result["missing_keys"] + +