feat: add LiteLLM as AI gateway provider#344
Open
RheagalFire wants to merge 1 commit into
Open
Conversation
Author
|
cc @okisdev |
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
Motivation
LiteLLM acts as a unified AI gateway. Instead of configuring individual provider API keys, users can point ChatChat at a single LiteLLM proxy that handles provider routing across 100+ providers. Useful for self-hosters who already run a centralized LiteLLM proxy, or users who need providers not yet directly supported (e.g., AWS Bedrock, Vertex AI).
Changes
lib/provider/LiteLLM.ts- new OpenAI-compatible client pointing at LiteLLM proxy (configurable viaLITELLM_BASE_URLandLITELLM_API_KEYenv vars)config/provider/litellm.ts- model definitions with example LiteLLM model IDs (openai/gpt-4o-mini,anthropic/claude-3-5-sonnet,openai/gpt-4o)config/provider/index.ts- addedLiteLLMto Provider enum, AllModelId/AllModelName unions, and Providers listapp/api/chat/messages/route.ts- addedcase Provider.LiteLLM:using OpenAI-compatible streaming (same pattern as Fireworks/Perplexity)Tests
Live E2E - basic completion via LiteLLM proxy routing to Claude Sonnet 4.6:
Live E2E - streaming via LiteLLM proxy:
Streaming chunks accumulated correctly through the same
OpenAIStreampath ChatChat uses for Fireworks/Perplexity.Error handling - invalid model:
All 3 tests use the exact same
new OpenAI({ baseURL, apiKey })client thatlib/provider/LiteLLM.tsexports.Risk / Compatibility
openaipackage since LiteLLM proxy serves an OpenAI-compatible API.http://localhost:4000/v1(standard LiteLLM proxy port).Example usage
1. Start a LiteLLM proxy:
2. Set environment variables in
.env.local:3. Select "LiteLLM" as provider in ChatChat settings, then use any LiteLLM model ID:
Users can also point at a remote LiteLLM proxy for centralized credential management: