mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-09 08:18:12 +00:00
fix: validate_environment returns false all-clear for zai when ZAI_API_KEY unset (fixes #32962)
Signed-off-by: Aloys Jehwin <aloys.jehwin@sap.com>
This commit is contained in:
parent
6a797f97b2
commit
25921d59fd
2 changed files with 40 additions and 0 deletions
|
|
@ -6141,6 +6141,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 (
|
||||
|
|
|
|||
35
tests/local_testing/test_validate_environment_zai.py
Normal file
35
tests/local_testing/test_validate_environment_zai.py
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
# SPDX-License-Identifier: MIT
|
||||
# Tests for validate_environment fix: zai provider was missing from the
|
||||
# elif chain in litellm/utils.py, causing a false all-clear when ZAI_API_KEY
|
||||
# is unset (fixes #32962).
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
|
||||
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..")))
|
||||
|
||||
import litellm
|
||||
|
||||
|
||||
def test_zai_missing_key_reports_missing(monkeypatch):
|
||||
monkeypatch.delenv("ZAI_API_KEY", raising=False)
|
||||
result = litellm.validate_environment(model="zai/glm-5.1")
|
||||
assert result["keys_in_environment"] is False
|
||||
assert "ZAI_API_KEY" in result["missing_keys"]
|
||||
|
||||
|
||||
def test_zai_key_present_reports_ok(monkeypatch):
|
||||
monkeypatch.setenv("ZAI_API_KEY", "test-key-123")
|
||||
result = litellm.validate_environment(model="zai/glm-5.1")
|
||||
assert result["keys_in_environment"] is True
|
||||
assert "ZAI_API_KEY" not in result["missing_keys"]
|
||||
|
||||
|
||||
def test_moonshot_missing_key_still_reports_missing(monkeypatch):
|
||||
"""Regression: moonshot neighbour branch still works after the zai addition."""
|
||||
monkeypatch.delenv("MOONSHOT_API_KEY", raising=False)
|
||||
result = litellm.validate_environment(model="moonshot/kimi-k2")
|
||||
assert result["keys_in_environment"] is False
|
||||
assert "MOONSHOT_API_KEY" in result["missing_keys"]
|
||||
Loading…
Add table
Reference in a new issue