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(ai21): resolve the documented AI21_API_KEY instead of a misspelled name (#35985)
Yassin Kortam8ec562f279da
diff --git a/litellm/utils.py b/litellm/utils.pyindex 3795262a6c0..d93c88e05a0 100644--- a/litellm/utils.py+++ b/litellm/utils.py@@ -4789,7 +4789,7 @@ def get_api_key(llm_provider: str, dynamic_api_key: str | None):api_key = api_key or litellm.anthropic_key or get_secret("ANTHROPIC_API_KEY")# ai21elif llm_provider == "ai21":- api_key = api_key or litellm.ai21_key or get_secret("AI211_API_KEY")+ api_key = api_key or litellm.ai21_key or get_secret("AI21_API_KEY")# aleph_alphaelif llm_provider == "aleph_alpha":api_key = api_key or litellm.aleph_alpha_key or get_secret("ALEPH_ALPHA_API_KEY")diff --git a/tests/test_litellm/test_utils.py b/tests/test_litellm/test_utils.pyindex f1f863b99a0..a8eb8b11974 100644--- a/tests/test_litellm/test_utils.py+++ b/tests/test_litellm/test_utils.py@@ -26,6 +26,7 @@ from litellm.utils import (TextCompletionStreamWrapper,_check_provider_match,_is_streaming_request,+ get_api_key,get_llm_provider,get_optional_params_image_gen,get_prompt_cache_min_tokens,@@ -5108,3 +5109,14 @@ def test_reapply_runtime_registrations_drops_request_scoped_registrations(monkeyfinally:litellm.model_cost = saved_model_cost_invalidate_model_cost_lowercase_map()+++def test_ai21_api_key_is_resolved_from_the_documented_env_var(monkeypatch: pytest.MonkeyPatch) -> None:+ """The ai21 branch resolved a misspelled env var, so the name every other ai21 code path+ reads, and the only name documented, was ignored."""+ monkeypatch.setattr(litellm, "api_key", None)+ monkeypatch.setattr(litellm, "ai21_key", None)+ monkeypatch.delenv("AI211_API_KEY", raising=False)+ monkeypatch.setenv("AI21_API_KEY", "sk-ai21-resolved-from-env")++ assert get_api_key(llm_provider="ai21", dynamic_api_key=None) == "sk-ai21-resolved-from-env"