feat: add LiteLLM as AI gateway provider#514
feat: add LiteLLM as AI gateway provider#514RheagalFire wants to merge 3 commits intoAsyncFuncAI:mainfrom
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces the LiteLLMClient to integrate with numerous LLM providers, along with corresponding configuration updates and unit tests. The review feedback identifies several high-priority improvements for the new client, including addressing thread-safety concerns and incorrect field mappings during response parsing, particularly for streaming. Other recommendations include narrowing exception handling in retry logic to avoid unnecessary retries on logic errors, sanitizing logs to prevent the exposure of sensitive API data, and optimizing the configuration loading process by moving static dictionary definitions out of loops.
7115d1f to
0e3789d
Compare
rlm-wiki reviewPR Review:
|
Summary
LiteLLMClientModelClientpattern used by OpenAI, Bedrock, OpenRouter, etc.Prior art
Motivation
DeepWiki currently ships separate client files for each provider (OpenAI, Bedrock, Azure, OpenRouter, DashScope, Ollama). Users who want to use providers not covered by these clients (Anthropic direct, Groq,
Together, Fireworks, Mistral, etc.) have no path today. Issue #471 describes exactly this: a user trying to connect via LiteLLM proxy to vLLM couldn't get it working.
LiteLLM routes to 100+ providers through a single unified interface. Adding it as a native provider means users can access any supported provider by setting the appropriate env var and model name.
Changes
api/litellm_client.py-- newLiteLLMClient(ModelClient)with synccall(), asyncacall(), embedding support, and streaming supportapi/config.py-- registeredLiteLLMClientinCLIENT_CLASSESanddefault_mapapi/config/generator.json-- addedlitellmprovider entry withsupportsCustomModel: trueapi/pyproject.toml-- addedlitellm>=1.60.0,<2.0as optional dependencytests/unit/test_litellm_client.py-- 18 unit testsUsage and testing
1. Unit tests (17 passed, 1 skipped for missing boto3):
2. Live E2E against real provider (Anthropic via Azure AI Foundry):
Async completion verified:
Async content: Hello!
Message list input verified:
Content with messages: Hi there!
Example usage
Via generator.json config (recommended):
Set default_provider to litellm in api/config/generator.json and configure any LiteLLM-supported model:
{ "default_provider": "litellm", "providers": { "litellm": { "client_class": "LiteLLMClient", "default_model": "anthropic/claude-sonnet-4-20250514", "supportsCustomModel": true, "models": { "anthropic/claude-sonnet-4-20250514": {"temperature": 0.7} } } } }Via Python directly:
Risk / Compatibility