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
refactor(utils): remove the dead get_api_key provider-key resolver (#39260)
devin-ai-integration[bot]a701effbad9c
diff --git a/basedpyright-code-budget.json b/basedpyright-code-budget.jsonindex da788bf1ce3..5ba2e748e43 100644--- a/basedpyright-code-budget.json+++ b/basedpyright-code-budget.json@@ -108,10 +108,10 @@"limit": 38350},"reportUnknownParameterType": {- "limit": 19626+ "limit": 19625},"reportUnknownVariableType": {- "limit": 29890+ "limit": 29877},"reportUnnecessaryCast": {"limit": 111@@ -138,7 +138,7 @@"limit": 138},"reportUnusedImport": {- "limit": 543+ "limit": 542},"reportUnusedVariable": {"limit": 137diff --git a/litellm/main.py b/litellm/main.pyindex 01c106adc7c..0128e4defe5 100644--- a/litellm/main.py+++ b/litellm/main.py@@ -141,7 +141,6 @@ from litellm.utils import (convert_to_model_response_object,create_pretrained_tokenizer,create_tokenizer,- get_api_key,get_llm_provider,get_model_info,get_non_default_completion_params,diff --git a/litellm/utils.py b/litellm/utils.pyindex 252b6756937..ba456fc353b 100644--- a/litellm/utils.py+++ b/litellm/utils.py@@ -5106,49 +5106,6 @@ def get_response_string(response_obj: ModelResponse | ModelResponseStream) -> streturn "".join(response_parts)-def get_api_key(llm_provider: str, dynamic_api_key: str | None):- api_key = dynamic_api_key or litellm.api_key- # openai- if llm_provider == "openai" or llm_provider == "text-completion-openai":- api_key = api_key or litellm.openai_key or get_secret("OPENAI_API_KEY")- # anthropic- elif llm_provider == "anthropic" or llm_provider == "anthropic_text":- 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("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")- # baseten- elif llm_provider == "baseten":- api_key = api_key or litellm.baseten_key or get_secret("BASETEN_API_KEY")- # cohere- elif llm_provider == "cohere" or llm_provider == "cohere_chat":- api_key = api_key or litellm.cohere_key or get_secret("COHERE_API_KEY")- # huggingface- elif llm_provider == "huggingface":- api_key = api_key or litellm.huggingface_key or get_secret("HUGGINGFACE_API_KEY")- # nlp_cloud- elif llm_provider == "nlp_cloud":- api_key = api_key or litellm.nlp_cloud_key or get_secret("NLP_CLOUD_API_KEY")- # replicate- elif llm_provider == "replicate":- api_key = api_key or litellm.replicate_key or get_secret("REPLICATE_API_KEY")- # together_ai- elif llm_provider == "together_ai":- api_key = (- api_key or litellm.togetherai_api_key or get_secret("TOGETHERAI_API_KEY") or get_secret("TOGETHER_AI_TOKEN")- )- # nebius- elif llm_provider == "nebius":- api_key = api_key or litellm.nebius_key or get_secret("NEBIUS_API_KEY")- # wandb- elif llm_provider == "wandb":- api_key = api_key or litellm.wandb_key or get_secret("WANDB_API_KEY")- return api_key--def get_utc_datetime():import datetime as dtfrom datetime import datetimediff --git a/ruff-strict-budget.json b/ruff-strict-budget.jsonindex 9b1cc977a64..ae91b711e13 100644--- a/ruff-strict-budget.json+++ b/ruff-strict-budget.json@@ -9,7 +9,7 @@"limit": 809},"ANN201": {- "limit": 2001+ "limit": 2000},"ANN202": {"limit": 835@@ -108,7 +108,7 @@"limit": 3},"F401": {- "limit": 13+ "limit": 12},"LOG015": {"limit": 5@@ -147,7 +147,7 @@"limit": 3},"PLR1714": {- "limit": 256+ "limit": 253},"PLW0127": {"limit": 57diff --git a/tests/test_litellm/test_utils.py b/tests/test_litellm/test_utils.pyindex 0790b41c349..200cfd02197 100644--- a/tests/test_litellm/test_utils.py+++ b/tests/test_litellm/test_utils.py@@ -41,7 +41,6 @@ from litellm.utils import (_snapshot_exception_for_hook,async_post_call_failure_deployment_hook,client,- get_api_key,get_llm_provider,get_non_default_completion_params,get_optional_params_image_gen,@@ -4917,17 +4916,6 @@ def test_reapply_runtime_registrations_drops_request_scoped_registrations(monkey_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"--class _JsonCapture(logging.Handler):def __init__(self):super().__init__()diff --git a/type-discipline-budget.json b/type-discipline-budget.jsonindex 52cb9628252..93eb8fac0ca 100644--- a/type-discipline-budget.json+++ b/type-discipline-budget.json@@ -27,7 +27,7 @@"limit": 0},"LIT010": {- "limit": 16507+ "limit": 16494},"LIT011": {"limit": 5535