LiteLLM 速查表
LiteLLM 是一个轻量级的 LLM API 代理,为 100+ 模型提供统一的 OpenAI 兼容接口。支持费用追踪、速率限制、模型回退、负载均衡等企业级功能,是管理多模型 API 调用的标准方案。
更新: 2026-07-20·12 条命令
快速开始
``bash
# 安装
pip install litellm
# 为单个模型启动代理 litellm --model gpt-4o --port 4000
# 测试 curl -s http://localhost:4000/v1/chat/completions \ -d '{"model":"gpt-4o","messages":[{"role":"user","content":"你好"}]}'
# 查看可用模型
curl -s http://localhost:4000/v1/models | jq .
`
单模型模式
litellm --model <名称> 快速启动。支持所有 OpenAI 兼容模型,以及 Claude、Gemini、Llama 等 100+ 模型。
多模型配置
生产环境使用 YAML 配置文件管理多个模型,每个模型可指定不同提供商、速率限制和费用设置。/v1/models 端点列出所有可用模型。
费用管理
--max-budget` 设置月度硬上限。LiteLLM 记录每次请求的模型、tokens 和费用。支持按 API Key 或用户设置独立限额。
启动模式(2)
| 命令 | 难度 | ||
|---|---|---|---|
litellm --help显示 LiteLLM 帮助 | 基础 | litellm --help | |
pip install litellm安装 LiteLLM | 基础 | pip install litellm |
ai-server(10)
| 命令 | 难度 | ||
|---|---|---|---|
litellm --model指定模型并启动代理(核心用法) | 基础 | litellm --model gpt-4o --port 4000 | |
litellm --model --port指定代理端口 | 基础 | litellm --model claude-3-opus --port 4000 | |
litellm --config使用配置文件启动代理 | 中级 | litellm --config ./litellm_config.yaml --port 4000 | |
litellm --drop-params在请求中省略敏感参数 | 中级 | litellm --model gpt-4o --drop-params api_key | |
litellm --max-budget设置每月费用上限 | 中级 | litellm --model gpt-4o --max-budget 50.0 | |
curl localhost:4000/v1/chat/completions通过代理发送 OpenAI 兼容请求 | 中级 | curl -s http://localhost:4000/v1/chat/completions -d '{"model":"gpt-4o","messages":[{"role":"user","content":"Hello"}]}'
| |
curl localhost:4000/v1/models查看代理可用的模型列表 | 基础 | curl -s http://localhost:4000/v1/models | jq . | |
curl localhost:4000/health检查代理健康状态 | 基础 | curl -s http://localhost:4000/health | |
litellm --num_requests设置最大并发请求数 | 中级 | litellm --model gpt-4o --num_requests 10 | |
litellm --request_timeout设置请求超时时间(秒) | 中级 | litellm --model gpt-4o --request_timeout 600 |
常见问题
本速查表数据整理自各工具官方文档。最后更新: 2026-07-20。