LiteLLM
BerriAI / litellm
把 100+ 模型 API 统一成 OpenAI 兼容格式的网关与 SDK:Rust 核心、虚拟密钥、成本追踪、限流/负载均衡、guardrails、日志与缓存,可自托管。A gateway and SDK that normalises 100+ model APIs into an OpenAI-compatible format, with a Rust core, virtual keys, cost tracking, rate limits, load balancing, guardrails, logging and caching, self-hostable.
为什么选Why choose it
- 换模型只改 model 名,不用重写调用层;多上游路由与 fallback 在一处配。One API shape across providers.
- 团队用虚拟 key 做配额与成本归集,比每人一把上游 key 更可审计。Virtual keys, budgets and rate limits centralise control.
- Rust 核心 + Python SDK,适合做内部 AI 网关,也能直接嵌进应用。Self-hosting keeps logs and keys in your infrastructure.
不适合Not for
它不是推理引擎;本地模型仍要 vLLM、Ollama 等后端。You use one provider and one key with no routing needs.
代理层能看到 prompt 与密钥,必须自己做网络、日志脱敏与权限隔离。You cannot operate a gateway service.
企业目录另有许可,不能把整仓当成纯 MIT 使用。企业目录另有许可,不能把整仓当成纯 MIT 使用。
最小上手Minimum setup
- 用官方 Docker 镜像或 pip install "litellm[proxy]" 起服务,先接一个 OpenAI 兼容上游。Route two providers through one virtual key.
- 在 config.yaml 配 model_list、virtual key 与预算,用一个 SDK 请求验证路由。Set a budget and a rate limit, then test both.
- 再打开 spend tracking 与日志,确认 prompt 不会落到不该去的地方。Check that logs redact prompts and keys as expected.
依赖与成本Dependencies and cost
Python 3.9+ / Docker;至少一个上游模型 API 或本地推理后端;生产要 Redis/Postgres(配额、缓存、日志)与反向代理。Check runtime, model weights and external service dependencies in the README.
许可与使用边界License and usage boundaries
代码为 MIT + 企业目录单独许可;企业功能、第三方模型与数据各自条款,商用前读 LICENSE 与 enterprise/LICENSE。Code is MIT + Enterprise; model weights, training data and generated content may have separate terms — check each before commercial use.
开源不等于可商用:GPL / AGPL 有传染性;代码许可、模型许可、生成内容许可要分开看。上线前读仓库 LICENSE 与模型卡,必要时让法务确认。Open source is not automatically commercial-use friendly: GPL / AGPL are copyleft; code, model and output licenses are separate. Read the LICENSE and model card before launch, and involve legal when needed.
替代与相邻Alternatives and neighbors
- vLLM — 规模 / 性能Scale / performance,高吞吐推理与服务引擎,PagedAttention、连续批处理、多卡并行。A high-throughput inference and serving engine with PagedAttention, continuous batching and multi-GPU support.
- Ollama — 先试这个Start here,一条命令拉模型、跑本地推理,自带模型库与 OpenAI 兼容 API。Pull and run local models with one command, with a built-in model library and an OpenAI-compatible API.
- LocalAI — 本地优先Local-first,本地 OpenAI 兼容 API,支持文本、图像、语音等多模态后端。A local OpenAI-compatible API supporting text, image and speech backends.
下一步Next steps
- 打开 GitHub,先读 README、LICENSE、最近 release 与 issue。Open GitHub and read the README, LICENSE, latest release and issues first.
- 按“部署依赖 / 显存 / 数据 / 网络 / 权限”列一张上手清单。Make an onboarding checklist for deployment dependencies, VRAM, data, network and permissions.
- 用一个小样本跑通,再决定是否进生产;不要直接上生产数据。Run a small sample first, then decide on production; never start with production data.
GitHub 仓库 ↗GitHub repository ↗ 文档 ↗Docs ↗ 加入对比Add to compare