Feat/add litellm provider - #93
Open
RheagalFire wants to merge 2 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds LiteLLM as a first-class provider, enabling access to 100+ LLM providers (OpenAI, Anthropic, Google Gemini, AWS Bedrock, Azure OpenAI, Mistral, Cohere, and more) through Mercury's existing provider system via a LiteLLM proxy.
Changes
src/utils/config.ts- AddedlitellmtoProviderNameunion, config defaults (LITELLM_API_KEY,LITELLM_BASE_URL,LITELLM_MODEL,LITELLM_ENABLED), keyless proxy support inisProviderConfigured()src/providers/registry.ts- Registered litellm asOpenAICompatProvidersrc/providers/openai-compat.ts- FixedisAvailable()for keyless proxies (checksbaseUrlinstead ofapiKeyfor litellm/ollama), addedformatApiError()with specific messages for 401/404/429src/utils/provider-models.ts- LiteLLM-specific error message for model fetch failures, added litellm to model ID filtersrc/web/api/providers.ts- Fixed/api/providers/:name/testendpoint for keyless proxy testingTests
Tests (66/67 passing):
66 pass. 1 pre-existing failure in
tokens.test.ts(locale-dependent number formatting, unrelated to this change).Error handling:
[litellm] Authentication failed - check your API key or proxy credentials.[litellm] Model not found - verify the model name and base URL.[litellm] Rate limited - wait a moment before retrying.isAvailable()now checksbaseUrlinstead ofapiKeyMercury could not fetch models from the LiteLLM proxy. Please check the base URL and ensure the proxy is running.Risk / Compatibility
OpenAICompatProviderclass.LITELLM_ENABLED=trueenv var.Example usage
1. Start a LiteLLM proxy (manages models + API keys server-side):
pip install litellm litellm --model openai/gpt-4o --model anthropic/claude-sonnet-4-20250514 # Proxy running at http://localhost:40002. Configure Mercury via env vars:
3. Use in code - Mercury routes through the LiteLLM provider:
4. Under the hood - Mercury calls the LiteLLM proxy via Vercel AI SDK: