Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion litellm/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
# ai21
elif 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_alpha
elif llm_provider == "aleph_alpha":
api_key = api_key or litellm.aleph_alpha_key or get_secret("ALEPH_ALPHA_API_KEY")
Expand Down
12 changes: 12 additions & 0 deletions tests/test_litellm/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
TextCompletionStreamWrapper,
_check_provider_match,
_is_streaming_request,
get_api_key,
get_llm_provider,
get_optional_params_image_gen,
get_prompt_cache_min_tokens,
Expand Down Expand Up @@ -5108,3 +5109,14 @@ def test_reapply_runtime_registrations_drops_request_scoped_registrations(monkey
finally:
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"
Loading