LiteLLM Proxy
Unify 100+ cloud and local LLM providers behind one OpenAI-compatible gateway with fallbacks, retries, and hard spend caps.把 100+ 云端与本地大模型统一封装成一个 OpenAI 兼容网关,自带多源自动降级、限流重试与硬预算上限。
01 Friction Solved消除的小摩擦
Every AI provider speaks slightly different auth headers, rate-limit codes, and model IDs, and wiring fallback logic across free tiers plus paid backups inside application code quickly becomes brittle spaghetti. LiteLLM Proxy centralizes provider keys, automatic failover on 429/5xx, and per-key budget limits in one YAML config.各家模型平台的鉴权方式、限流错误码和模型 ID 各不相同,在业务代码里手写“主模型 → 备用免费层 → 本地模型”的降级逻辑既脆弱又难维护。LiteLLM Proxy 用一份 YAML 集中管理所有上游 Key、429/5xx 自动切换与单 Key 费用熔断。
02 Best-Fit Scenarios最适合的使用场景
- Routing side projects across free cloud tiers (Gemini, Groq, OpenRouter) with automatic fallback to local Ollama on 429.
- Issuing virtual API keys with strict dollar/RPM caps to autonomous agents so a runaway loop can never drain your billing account.
- Swapping underlying models or A/B testing providers without modifying or redeploying client applications.
- 把多个云端免费层(Gemini、Groq、OpenRouter)与本地 Ollama 编排成统一端点,遇到 429 自动无感切换。
- 给自动化 Agent 签发带硬性费用与速率上限的虚拟 Key,彻底杜绝死循环刷爆真实账单。
- 在不改一行客户端代码的前提下随时切换底层模型或做供应商对比测试。
03 Human & Agent Setup人类与 Agent 快速接入
model_list:
- model_name: default-chat
litellm_params:
model: groq/llama-3.3-70b-versatile
api_key: os.environ/GROQ_API_KEY
- model_name: default-chat
litellm_params:
model: ollama/qwen2.5-coder:7b
api_base: http://localhost:11434
router_settings:
routing_strategy: simple-shuffle
num_retries: 2
timeout: 30
# Start gateway: litellm --config config.yaml --port 4000
04 Reality Check & Trade-offs真实边界与局限
- Running the full proxy with spend tracking and virtual keys requires PostgreSQL; for solo local routing without persistence, a stateless YAML config is much lighter.
- Adds a local network hop and a Python service to keep running—overkill if you only call a single stable provider in a quick script.
- Provider parameter quirks (like tool-call schemas or reasoning_effort) still vary; always test structured outputs on every fallback target.
- 开启完整账单统计与虚拟 Key 管理需要搭配 PostgreSQL;个人本地只需路由降级时,用无状态 YAML 模式会轻很多。
- 多引入了一层常驻 Python 网关进程,如果只是单个脚本调一家稳定厂商,直接用官方 SDK 更省事。
- 各厂商对工具调用、JSON Schema 或推理参数的支持细节仍有差异,务必对每条降级链路做实际回归测试。
05 Why VYAGENT Picked ItVYAGENT 选品评语
Essential infrastructure once you graduate from one API key to a multi-provider stack or autonomous agents that need hard spend guardrails.当你从“单个 Key 尝鲜”进阶到多供应商编排或让 Agent 自主干活时,LiteLLM Proxy 是给账单和可用性兜底的关键基础设施。
06 Frequently Asked Questions常见问题 (FAQ)
Does LiteLLM Proxy work without a database?不装数据库能跑 LiteLLM Proxy 吗?
Yes. Stateless routing, retries, and fallbacks work directly from config.yaml without PostgreSQL. A database is only needed for virtual key management and persistent spend logs.可以。仅用 config.yaml 即可运行多模型路由、重试和自动降级;只有需要签发虚拟 Key 和持久化账单日志时才需要 PostgreSQL。
How does it protect against runaway agent loops?它如何防止 Agent 死循环刷爆账单?
You can set max_budget, rpm_limit, and tpm_limit per virtual key or model group, automatically rejecting requests once the threshold is reached.可按虚拟 Key 或模型组配置 max_budget、rpm_limit 和 tpm_limit,一旦触达阈值立即拒绝请求,防止费用失控。