Skip to content

feat: add LiteLLM as AI gateway provider#344

Open
RheagalFire wants to merge 1 commit into
okisdev:mainfrom
RheagalFire:feat/add-litellm-provider
Open

feat: add LiteLLM as AI gateway provider#344
RheagalFire wants to merge 1 commit into
okisdev:mainfrom
RheagalFire:feat/add-litellm-provider

Conversation

@RheagalFire
Copy link
Copy Markdown

Summary

  • Adds LiteLLM as a new provider, enabling users to route chat through 100+ LLM providers (OpenAI, Anthropic, Azure, Bedrock, Vertex AI, Groq, Ollama, etc.) via a single LiteLLM proxy.
  • Follows the existing provider pattern exactly (same structure as Fireworks/Perplexity - OpenAI-compatible client with custom baseURL).

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 via LITELLM_BASE_URL and LITELLM_API_KEY env 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 - added LiteLLM to Provider enum, AllModelId/AllModelName unions, and Providers list
  • app/api/chat/messages/route.ts - added case 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:

=== Test 1: Basic completion ===
Model: claude-sonnet-4-6
Content: OK
Finish reason: stop

Live E2E - streaming via LiteLLM proxy:

=== Test 2: Streaming ===
Streamed content: Hello!

Streaming chunks accumulated correctly through the same OpenAIStream path ChatChat uses for Fireworks/Perplexity.

Error handling - invalid model:

=== Test 3: Invalid model error handling ===
Handled gracefully, no crash

=== All tests passed ===

All 3 tests use the exact same new OpenAI({ baseURL, apiKey }) client that lib/provider/LiteLLM.ts exports.

Risk / Compatibility

  • Additive only. No existing providers modified.
  • No new dependencies - uses the existing openai package since LiteLLM proxy serves an OpenAI-compatible API.
  • Default proxy URL is http://localhost:4000/v1 (standard LiteLLM proxy port).

Example usage

1. Start a LiteLLM proxy:

pip install litellm
litellm --model anthropic/claude-3-5-sonnet --port 4000

2. Set environment variables in .env.local:

LITELLM_BASE_URL=http://localhost:4000/v1
LITELLM_API_KEY=sk-your-litellm-key

3. Select "LiteLLM" as provider in ChatChat settings, then use any LiteLLM model ID:

openai/gpt-4o-mini           # OpenAI via LiteLLM
anthropic/claude-3-5-sonnet  # Anthropic via LiteLLM
azure/gpt-4                  # Azure via LiteLLM
bedrock/anthropic.claude-3   # AWS Bedrock via LiteLLM
vertex_ai/gemini-pro         # Vertex AI via LiteLLM

Users can also point at a remote LiteLLM proxy for centralized credential management:

LITELLM_BASE_URL=https://my-proxy.example.com/v1
LITELLM_API_KEY=sk-team-key

@RheagalFire
Copy link
Copy Markdown
Author

cc @okisdev

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.

1 participant