Skip to content

feat: make LiteLLM API key optional for self-hosted instances#11920

Draft
roomote-v0[bot] wants to merge 1 commit intomainfrom
feature/litellm-optional-api-key
Draft

feat: make LiteLLM API key optional for self-hosted instances#11920
roomote-v0[bot] wants to merge 1 commit intomainfrom
feature/litellm-optional-api-key

Conversation

@roomote-v0
Copy link
Contributor

@roomote-v0 roomote-v0 bot commented Mar 13, 2026

Related GitHub Issue

Closes: #11918

Description

This PR attempts to address Issue #11918. The LiteLLM provider previously required a mandatory API Key, but LiteLLM is often used without authentication in self-hosted or local environments. This change makes the API Key optional while keeping the Base URL required.

Key changes:

  • webview-ui/src/utils/validate.ts: Changed the LiteLLM validation to require only litellmBaseUrl (not litellmApiKey)
  • webview-ui/src/components/settings/providers/LiteLLM.tsx: Updated handleRefreshModels and the Refresh Models button to only require a Base URL
  • src/shared/api.ts: Made apiKey optional in the litellm type definition
  • src/core/webview/webviewMessageHandler.ts: Changed the model fetch condition to only require litellmBaseUrl
  • src/api/providers/fetchers/litellm.ts: Updated getLiteLLMModels to accept string | undefined for apiKey, skip Authorization header when absent
  • src/api/providers/lite-llm.ts: Use empty string instead of "dummy-key" fallback so no unnecessary Authorization header is sent
  • webview-ui/src/i18n/locales/en/settings.json: Added baseUrl validation translation key

The fetcher already had logic to conditionally include the Authorization header only when an API key is provided, so the main work was removing the mandatory validation and adjusting types/conditions throughout the codebase.

Feedback and guidance are welcome.

Test Procedure

  • Added 3 new tests in webview-ui/src/utils/__tests__/validate.spec.ts for LiteLLM validation:
    • Valid config with Base URL but no API key (should pass)
    • Missing Base URL (should return error)
    • Valid config with both Base URL and API key (should pass)
  • Added 1 new test in src/api/providers/fetchers/__tests__/litellm.spec.ts for undefined API key case
  • All existing tests continue to pass (21 litellm fetcher tests, 23 validate tests)

Pre-Submission Checklist

  • Issue Linked: This PR is linked to an approved GitHub Issue (see "Related GitHub Issue" above).
  • Scope: My changes are focused on the linked issue (one major feature/fix per PR).
  • Self-Review: I have performed a thorough self-review of my code.
  • Testing: New and/or updated tests have been added to cover my changes.
  • Documentation Impact: No documentation updates needed - this is a UX/validation fix.
  • Contribution Guidelines: I have read and agree to the Contributor Guidelines.

Interactively review PR in Roo Code Cloud

The LiteLLM provider now only requires a Base URL. The API Key field
is optional, allowing users with self-hosted or local LiteLLM proxies
to use the extension without entering a dummy key.

Changes:
- validate.ts: require only litellmBaseUrl (not litellmApiKey) for LiteLLM
- LiteLLM.tsx: allow Refresh Models with just a Base URL
- shared/api.ts: make apiKey optional in litellm type
- webviewMessageHandler.ts: fetch models when baseUrl is set (no key needed)
- litellm.ts fetcher: accept undefined apiKey, skip Auth header when absent
- lite-llm.ts handler: use empty string instead of "dummy-key" fallback
- Added "baseUrl" validation translation key
- Added tests for optional API key scenarios

Fixes #11918
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.

[Bug]: LiteLLM provider should not require a mandatory API Key

1 participant