fix(litellm_proxy): add "fake-api-key" fallback when LITELLM_PROXY_API_KEY is not set - #20926
fix(litellm_proxy): add "fake-api-key" fallback when LITELLM_PROXY_API_KEY is not set#20926ritsuki1227 wants to merge 1 commit into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Greptile OverviewGreptile SummaryAdded
Confidence Score: 5/5
|
| Filename | Overview |
|---|---|
| litellm/llms/litellm_proxy/chat/transformation.py | Added or "fake-api-key" fallback to _get_openai_compatible_provider_info and get_api_key methods, plus a docstring correction. Follows the exact same pattern as hosted_vllm, lm_studio, and llamafile providers. |
| litellm/llms/litellm_proxy/image_edit/transformation.py | Added or "fake-api-key" fallback to validate_environment. Straightforward change consistent with other litellm_proxy transformation files. |
| litellm/llms/litellm_proxy/image_generation/transformation.py | Added or "fake-api-key" fallback to validate_environment and a minor formatting fix (blank line after docstring). Consistent with other files. |
| litellm/llms/litellm_proxy/responses/transformation.py | Added new validate_environment override that uses LITELLM_PROXY_API_KEY with "fake-api-key" fallback instead of inheriting OpenAI's default which would fall through to OPENAI_API_KEY. Method signature correctly matches parent class OpenAIResponsesAPIConfig.validate_environment. |
| tests/test_litellm/llms/litellm_proxy/chat/test_litellm_proxy_chat_transformation.py | Added well-structured parametrized tests for _get_openai_compatible_provider_info and get_api_key, plus two E2E mock tests verifying the fake-api-key fallback and OPENAI_API_KEY isolation. All tests use mocks only. |
| tests/test_litellm/llms/litellm_proxy/image_edit/test_litellm_proxy_image_edit_transformation.py | New test file with parametrized tests covering all API key fallback scenarios for image edit. Mock-only, no network calls. |
| tests/test_litellm/llms/litellm_proxy/image_generation/test_litellm_proxy_image_generation_transformation.py | New test file with parametrized tests covering all API key fallback scenarios for image generation. Mock-only, no network calls. |
| tests/test_litellm/llms/litellm_proxy/responses/test_litellm_proxy_responses_transformation.py | New test file with parametrized tests plus an explicit test that OPENAI_API_KEY is not leaked to the proxy. Mock-only, no network calls. |
f29efd7 to
4c0c78b
Compare
|
@krrishdholakia This PR is ready for review. CI note: The only failing checks are repo-wide issues unrelated to this PR:
Also note that #20947 appears to be a duplicate of this PR, covering only the |
4c0c78b to
cdc76f8
Compare
|
@ishaan-jaff @krrishdholakia Friendly bump — rebased onto latest main, CI is green now. This is a small fix (1 commit, 8 files) adding the |
|
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
Changes
Add or "fake-api-key" fallback to the litellm_proxy provider, matching the existing pattern in hosted_vllm, lm_studio, llamafile, and datarobot.
This enables keyless authentication scenarios (service mesh with mTLS, VPC-internal, local development) where the LiteLLM proxy runs with master_key=None.
Why "fake-api-key" and not ""?
The fallback value must be truthy. In main.py:2366-2371, there is an or-chain:
api_key = api_key or litellm.api_key or litellm.openai_key or get_secret("OPENAI_API_KEY")
An empty string "" is falsy and would fall through to OPENAI_API_KEY, potentially leaking unrelated credentials to the proxy. "fake-api-key" is truthy and stops the chain.
Relevant issues
Fixes #20925
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
tests/litellm/directory, Adding at least 1 test is a hard requirement - see detailsmake test-unitCI (LiteLLM team)
Branch creation CI run
Link:
CI run for the last commit
Link:
Merge / cherry-pick CI run
Links:
Type
🆕 New Feature
🐛 Bug Fix
🧹 Refactoring
📖 Documentation
🚄 Infrastructure
✅ Test
Changes