Skip to content

fix(litellm_proxy): add "fake-api-key" fallback when LITELLM_PROXY_API_KEY is not set - #20926

Closed
ritsuki1227 wants to merge 1 commit into
BerriAI:mainfrom
ritsuki1227:feat/auth
Closed

fix(litellm_proxy): add "fake-api-key" fallback when LITELLM_PROXY_API_KEY is not set#20926
ritsuki1227 wants to merge 1 commit into
BerriAI:mainfrom
ritsuki1227:feat/auth

Conversation

@ritsuki1227

@ritsuki1227 ritsuki1227 commented Feb 11, 2026

Copy link
Copy Markdown

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

  • I have Added testing in the tests/litellm/ directory, Adding at least 1 test is a hard requirement - see details
  • My PR passes all unit tests on make test-unit
  • My PR's scope is as isolated as possible, it only solves 1 specific problem

CI (LiteLLM team)

CI status guideline:

  • 50-55 passing tests: main is stable with minor issues.
  • 45-49 passing tests: acceptable but needs attention
  • <= 40 passing tests: unstable; be careful with your merges and assess the risk.
  • 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

@vercel

vercel Bot commented Feb 11, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
litellm Ready Ready Preview, Comment Feb 22, 2026 7:14am

Request Review

@CLAassistant

CLAassistant commented Feb 11, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@greptile-apps

greptile-apps Bot commented Feb 11, 2026

Copy link
Copy Markdown
Contributor

Greptile Overview

Greptile Summary

Added "fake-api-key" fallback across all four litellm_proxy sub-providers (chat, image_edit, image_generation, responses) so the proxy can be used without setting LITELLM_PROXY_API_KEY. This matches the established pattern in hosted_vllm, lm_studio, llamafile, and datarobot providers. The truthy "fake-api-key" value prevents the or-chain in main.py from falling through to OPENAI_API_KEY, avoiding credential leakage to the proxy.

  • The responses sub-provider previously had no validate_environment override and was inheriting OpenAIResponsesAPIConfig's default, which would resolve to OPENAI_API_KEY — a bug when the proxy doesn't need authentication. A new override was added with the correct provider-specific fallback chain.
  • Whitespace/formatting cleanups in image_generation/transformation.py and responses/transformation.py.
  • Comprehensive parametrized tests added for all four sub-providers, covering user-provided keys, env var keys, and the "fake-api-key" fallback. Two additional E2E mock tests verify that OPENAI_API_KEY is never leaked to the proxy.

Confidence Score: 5/5

  • This PR is safe to merge — it applies a well-established fallback pattern consistently across the litellm_proxy provider with thorough test coverage.
  • The change is minimal and follows an identical pattern already used in 5+ other providers. The method signatures match parent classes correctly. Tests are comprehensive, mock-only, and cover all edge cases including credential isolation. No breaking changes or performance concerns.
  • No files require special attention.

Important Files Changed

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.

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

8 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@ritsuki1227

Copy link
Copy Markdown
Author

@krrishdholakia This PR is ready for review.

CI note: The only failing checks are repo-wide issues unrelated to this PR:

  • lint: litellm_pre_call_utils.py (PLR0915) and pipeline_executor.py (F841) — not touched by this PR
  • test matrix: poetry.lock / pyproject.toml mismatch — affects all open PRs
  • unit-test and validate-model-prices-json both pass

Also note that #20947 appears to be a duplicate of this PR, covering only the chat sub-provider. This PR was opened earlier and covers all 4 litellm_proxy sub-providers (chat, image_edit, image_generation, responses) with tests for each.

@ritsuki1227

Copy link
Copy Markdown
Author

@ishaan-jaff @krrishdholakia Friendly bump — rebased onto latest main, CI is green now.

This is a small fix (1 commit, 8 files) adding the "fake-api-key" fallback to the litellm_proxy provider, matching the existing pattern in hosted_vllm, lm_studio, llamafile, and datarobot. Fixes #20925.

@github-actions

Copy link
Copy Markdown
Contributor

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.

@github-actions github-actions Bot added the stale label May 24, 2026
@github-actions github-actions Bot closed this May 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: litellm_proxy provider raises AuthenticationError when LITELLM_PROXY_API_KEY is not set

2 participants