Repository navigation
refactor(utils): remove the dead get_api_key provider-key resolver - #39260
Conversation
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 EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
|
@greptileai please review this dead-code removal, in particular the public surface caveat on litellm.get_api_key |
|
|
|
PR #39260 (author devin-ai-integration[bot], repo BerriAI/litellm) carries no labels — the |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
@greptileai review |
Greptile SummaryThis PR removes the unused
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains.
|
| 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
|
@greptileai re-review please, the compatibility thread above is resolved and the code is unchanged at 11a7a4d |
a701eff
into
litellm_internal_staging
TLDR
Problem this solves:
litellm.utils.get_api_keyhas no callers anywhere in the repoget_llm_provideralready doesmain.pyalso published it aslitellm.get_api_keyHow it solves it:
main.pyimport, and its ai21 testUser 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
import litellm; litellm.get_api_key("openai", None)Nonefor the restAfter: the same import fails loudly instead of returning a partial answer
import litellm; litellm.get_api_key("openai", None)AttributeError: module 'litellm' has no attribute 'get_api_key'completion,get_llm_provider, ...) behaves exactly as before, see the live run belowRelevant 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
uv run pytest tests/test_litellm/<your_test_file>.py -v(tests/test_litellm/test_utils.py: 317 passed)@greptileaito 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=$PWDso the interpreter and the proxy load this checkout,litellm/proxy/dev_config.yamlunchanged, Postgres running,ANTHROPIC_API_KEYset in the environmentBefore (92d4533)
Import surface
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))'The function resolves at the top level of the package through
main.py's unused import, answers foropenai, and silently returnsNoneforbedrockand every other provider it does not listAfter (11a7a4d)
Import surface
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__)'Live proxy still serves a real completion
uv run --no-sync litellm --config litellm/proxy/dev_config.yaml --port 4000boots toGET /health/liveliness -> 200curl -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}'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 helperType
🧹 Refactoring
Caveats (if any)
Medium
litellm.get_api_keyandlitellm.utils.get_api_keystop resolving for external importers__init__.py, published only viamain.py's unused import and thefrom .main import *in__init__.pyBedrockLLMfrom the same star-exported import blockDeprecationWarningshim inutils.pyand removal on a majorLow
main.pyhaving no__all__solitellm.*gains or loses names whenever an import changes, is out of scope here and should get its own ticketosv-scancheck is red on this PR and on the last threelitellm_internal_stagingruns alike (pypdf and tornado advisories in the untoucheduv.lock), so it is inherited from the base, not introduced hereFinal Attestation
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