Skip to content

refactor(utils): remove the dead get_api_key provider-key resolver - #39260

Merged
yassin-berriai merged 1 commit into
litellm_internal_stagingfrom
litellm_remove_dead_get_api_key
Sep 2, 2026
Merged

yassin-berriai merged 1 commit into
litellm_internal_stagingfrom
litellm_remove_dead_get_api_key

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

TLDR

Problem this solves:

How it solves it:

  • Delete the function, the unused main.py import, and its ai21 test
  • Ratchet the ruff, type-discipline and basedpyright budgets it was consuming

User Flow

Before: nothing a proxy or SDK user does is affected, the function is dead code. The only visible effect of this PR is on a Python caller who reached the function by import

  1. A Python script runs import litellm; litellm.get_api_key("openai", None)
  2. It returns the resolved key, so the script keeps working even though the function only knows 12 of the 100+ providers and returns None for the rest

After: the same import fails loudly instead of returning a partial answer

  1. The same script runs import litellm; litellm.get_api_key("openai", None)
  2. It raises AttributeError: module 'litellm' has no attribute 'get_api_key'
  3. Every proxy route and SDK call (completion, get_llm_provider, ...) behaves exactly as before, see the live run below

Relevant issues

Follow-up to #35985, which fixed the misspelling but deliberately left the function in place so the removal could get its own review

Linear ticket

Resolves LIT-5245

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have added meaningful tests (n/a: this PR only deletes code, and a test asserting a name is absent would be a structure test; the deleted ai21 test was the only one that referenced the function)
  • The handful of test files covering my change pass locally, e.g. uv run pytest tests/test_litellm/<your_test_file>.py -v (tests/test_litellm/test_utils.py: 317 passed)
  • My PR passes all required CI/CD checks (e.g., lint, schema.d.ts sync check, etc.)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • I have received a Greptile Confidence Score of at least 4/5 (5/5 at 11a7a4d) before requesting a maintainer review (Greptile reviews automatically once the PR is opened; only comment @greptileai to re-request a review after pushing changes)

Delays in PR merge?

If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).

Screenshots / Proof of Fix

Shared setup: PYTHONPATH=$PWD so the interpreter and the proxy load this checkout, litellm/proxy/dev_config.yaml unchanged, Postgres running, ANTHROPIC_API_KEY set in the environment

Before (92d4533)

Import surface

  1. OPENAI_API_KEY=sk-proof-only uv run --no-sync python -c 'import inspect, litellm; print(inspect.getsourcefile(litellm.get_api_key), inspect.getsourcelines(litellm.get_api_key)[1]); print(litellm.get_api_key("openai", None)); print(litellm.get_api_key("bedrock", None))'
  2. Output:
/home/ubuntu/repos/litellm/litellm/utils.py 5109
sk-proof-only
None

The function resolves at the top level of the package through main.py's unused import, answers for openai, and silently returns None for bedrock and every other provider it does not list

After (11a7a4d)

Import surface

  1. OPENAI_API_KEY=sk-proof-only uv run --no-sync python -c 'import litellm, litellm.utils; print(hasattr(litellm, "get_api_key"), hasattr(litellm.utils, "get_api_key"), litellm.completion.__module__)'
  2. Output:
False False litellm.main

Live proxy still serves a real completion

  1. uv run --no-sync litellm --config litellm/proxy/dev_config.yaml --port 4000 boots to GET /health/liveliness -> 200
  2. curl -s http://localhost:4000/chat/completions -H "Authorization: Bearer sk-1234" -H "Content-Type: application/json" -d '{"model":"anthropic-haiku-4-5","messages":[{"role":"user","content":"Reply with exactly: get_api_key removed"}],"max_tokens":20}'
  3. Output (real Anthropic call, 17 prompt tokens and 9 completion tokens billed):
{"id":"chatcmpl-82de9809-3892-4d79-9708-fe93f49f4379","created":1788319769,"model":"anthropic-haiku-4-5","object":"chat.completion","choices":[{"finish_reason":"stop","index":0,"message":{"content":"get_api_key removed","role":"assistant","provider_specific_fields":{"citations":null,"thinking_blocks":null}}}],"usage":{"completion_tokens":9,"prompt_tokens":17,"total_tokens":26,...}}
  1. curl -s http://localhost:4000/models -H "Authorization: Bearer sk-1234" lists all 40 configured deployments, so provider resolution for the whole model list still works without the deleted helper

Type

🧹 Refactoring

Caveats (if any)

Medium

  • litellm.get_api_key and litellm.utils.get_api_key stop resolving for external importers
    • Undocumented, not in __init__.py, published only via main.py's unused import and the from .main import * in __init__.py
    • Precedent for removing such a name outright rather than deprecating first: refactor(bedrock): remove the dead BedrockLLM invoke code path #35188 deleted BedrockLLM from the same star-exported import block
    • If the maintainers prefer deprecate-first, the alternative is a DeprecationWarning shim in utils.py and removal on a major

Low

  • The wider problem the ticket surfaced, main.py having no __all__ so litellm.* gains or loses names whenever an import changes, is out of scope here and should get its own ticket
  • The non-required osv-scan check is red on this PR and on the last three litellm_internal_staging runs alike (pypdf and tornado advisories in the untouched uv.lock), so it is inherited from the base, not introduced here

Final Attestation

  • The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR

Link to Devin session: https://app.devin.ai/sessions/7d2f5ce02d6a4968925246a56c43960c
Open in Devin Desktop: https://app.devin.ai/desktop/session/7d2f5ce02d6a4968925246a56c43960c?variant=devin
Requested by: @yassin-berriai

get_api_key had no callers. main.py imported it without using it, and
because main.py declares no __all__, the star import in __init__.py
published it as litellm.get_api_key. It duplicated key resolution that
get_llm_provider_logic already performs, which is how a misspelled env
var survived in it unnoticed until #35985. Drop the definition, the
unused import, the test that pinned the ai21 branch, and ratchet the
lint budgets down by the violations it carried.

Resolves LIT-5245

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

@greptileai please review this dead-code removal, in particular the public surface caveat on litellm.get_api_key

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

PR #39260 (author devin-ai-integration[bot], repo BerriAI/litellm) carries no labels — the enterprise label is absent, so no risk label, product label, or Linear change was made. Exiting without mutations.

@codspeed

codspeed Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing litellm_remove_dead_get_api_key (11a7a4d) with litellm_internal_staging (92d4533)

Open in CodSpeed

@codecov

codecov Bot commented Sep 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

@greptileai review

@greptile-apps

greptile-apps Bot commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR removes the unused get_api_key resolver and its accidental package-level export.

  • Deletes the resolver and its AI21-specific test.
  • Removes the unused import from litellm/main.py.
  • Tightens static-analysis budgets to reflect the deleted code.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
litellm/utils.py Removes the dead provider-key resolver as intended.
litellm/main.py Removes the import that accidentally exposed the resolver at package level.
tests/test_litellm/test_utils.py Removes the test dedicated solely to the deleted resolver.
basedpyright-code-budget.json Ratchets type-checking budgets to account for the deleted code.
ruff-strict-budget.json Ratchets lint budgets to account for the removed function and import.
type-discipline-budget.json Lowers the affected type-discipline budget consistently with the deletion.

Reviews (2): Last reviewed commit: "refactor(utils): remove the dead get_api..." | Re-trigger Greptile

Comment thread litellm/main.py
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

@greptileai re-review please, the compatibility thread above is resolved and the code is unchanged at 11a7a4d

@yassin-berriai
yassin-berriai enabled auto-merge (squash) September 2, 2026 22:04
@yassin-berriai
yassin-berriai merged commit a701eff into litellm_internal_staging Sep 2, 2026
77 of 78 checks passed
@yassin-berriai
yassin-berriai deleted the litellm_remove_dead_get_api_key branch September 2, 2026 22:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants