如果你使用 DeepSeek、元宝 AI、Copilot、ChatGPT 等 AI 工具,协助配置轩辕镜像、编写 docker pull 命令、修改 Docker Compose 镜像地址、配置镜像加速、排查镜像拉取失败、分析报错日志等问题,请先让 AI 阅读并遵守轩辕镜像的规则文档。
只需在 AI 对话中先发送下面这句话即可:
请先完整阅读并严格遵守以下文档中的全部规则与要求:
https://xuanyuan.cloud/agents.md
在未充分阅读并理解该文档前,不要生成任何命令、配置、修改建议、故障排查方案或技术回答。后续所有输出都必须严格以该文档中的规范为最高优先级执行。查看 agents.md 用法指南与完整示范。国内用户首推 元宝 AI、DeepSeek 的深度思考模式,不推荐豆包 AI;Cursor 等编辑器可在对话 @ 该链接,或加入 User Rules。 若 AI 无法访问外链,可 打开说明文档 复制全文粘贴。文档会随站点更新,复制内容可能过期,建议定期检查。
🚅 LiteLLM
LiteLLM AI 网关
支持 100+ 种 LLM 的开源 AI 网关。可自托管。企业级就绪。以 OpenAI 格式调用任何 LLM。
LiteLLM 代理服务器(AI 网关) | 托管代理 | 企业版 | 网站
LiteLLM 是一个开源 AI 网关,为您提供单一、统一的接口,可使用 OpenAI 格式调用 100+ 种 LLM 提供商——包括 OpenAI、Anthropic、Gemini、Bedrock、Azure 等。
您可以将其用作 Python SDK 进行直接库集成,或部署 AI 网关(代理服务器) 作为团队或组织的集中式服务。
https://docs.litellm.ai/docs/simple_proxy https://docs.litellm.ai/docs/providers
跨提供商管理 LLM 调用很快会变得复杂——每种模型都有不同的 SDK、身份验证模式、请求格式和错误类型。LiteLLM 消除了这种摩擦:
Netflix
LLM - 调用 100+ 种 LLM(Python SDK + AI 网关)
https://docs.litellm.ai/docs/supported_endpoints - /chat/completions、/responses、/embeddings、/images、/audio、/batches、/rerank、/a2a、/messages 等。
uv add litellm
from litellm import completion
import os
os.environ["OPENAI_API_KEY"] = "your-openai-key"
os.environ["ANTHROPIC_API_KEY"] = "your-anthropic-key"
# OpenAI
response = completion(model="openai/gpt-4o", messages=[{"role": "user", "content": "Hello!"}])
# Anthropic
response = completion(model="anthropic/claude-sonnet-4-20250514", messages=[{"role": "user", "content": "Hello!"}])
https://docs.litellm.ai/docs/proxy/docker_quick_start - 设置虚拟密钥,发送第一个请求
uv tool install 'litellm[proxy]'
litellm --model gpt-4o
import openai
client = openai.OpenAI(api_key="anything", base_url="http://0.0.0.0:4000")
response = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "Hello!"}]
)
https://docs.litellm.ai/docs/providers
代理 - 调用 A2A 代理(Python SDK + AI 网关)
https://docs.litellm.ai/docs/a2a#add-a2a-agents - LangGraph、Vertex AI Agent Engine、Azure AI Foundry、Bedrock AgentCore、Pydantic AI
from litellm.a2a_protocol import A2AClient
from a2a.types import SendMessageRequest, MessageSendParams
from uuid import uuid4
client = A2AClient(base_url="http://localhost:10001")
request = SendMessageRequest(
id=str(uuid4()),
params=MessageSendParams(
message={
"role": "user",
"parts": [{"kind": "text", "text": "Hello!"}],
"messageId": uuid4().hex,
}
)
)
response = await client.send_message(request)
步骤 1. https://docs.litellm.ai/docs/a2a#adding-your-agent——为每个代理设置 protocolVersion 为 1.0 或 0.3
步骤 2. 通过 A2A SDK 调用代理(需 a2a-sdk>=1.1.0)
import httpx
from a2a.client import A2ACardResolver, ClientConfig, ClientFactory
from a2a.types import Message, Part, Role, SendMessageRequest
from a2a.utils.constants import TransportProtocol
from uuid import uuid4
base_url = "http://localhost:4000/a2a/my-agent" # LiteLLM proxy + agent name
headers = {"Authorization": "Bearer sk-1234"} # LiteLLM Virtual Key
async with httpx.AsyncClient(headers=headers, timeout=60.0) as http_client:
resolver = A2ACardResolver(httpx_client=http_client, base_url=base_url)
agent_card = await resolver.get_agent_card()
config = ClientConfig(
httpx_client=http_client,
streaming=False,
supported_protocol_bindings=[TransportProtocol.JSONRPC, TransportProtocol.HTTP_JSON],
)
client = ClientFactory(config).create(agent_card)
request = SendMessageRequest(
message=Message(
message_id=uuid4().hex,
role=Role.ROLE_USER,
parts=[Part(text="Hello!")],
)
)
async for event in client.send_message(request):
populated = event.ListFields()
if populated and populated[0][0].name in ("message", "msg"):
print("".join(getattr(p, "text", "") or "" for p in populated[0][1].parts))
https://docs.litellm.ai/docs/a2a
MCP 工具 - 将 MCP 服务器连接到任何 LLM(Python SDK + AI 网关)
from mcp import ClientSession, StdioServerParameters
from mcp.client.stdio import stdio_client
from litellm import experimental_mcp_client
import litellm
server_params = StdioServerParameters(command="python", args=["mcp_server.py"])
async with stdio_client(server_params) as (read, write):
async with ClientSession(read, write) as session:
await session.initialize()
# Load MCP tools in OpenAI format
tools = await experimental_mcp_client.load_mcp_tools(session=session, format="openai")
# Use with any LiteLLM model
response = await litellm.acompletion(
model="gpt-4o",
messages=[{"role": "user", "content": "What's 3 + 5?"}],
tools=tools
)
步骤 1. https://docs.litellm.ai/docs/mcp#adding-your-mcp
步骤 2. 通过 /chat/completions 调用 MCP 工具
curl -X POST 'http://0.0.0.0:4000/v1/chat/completions' \
-H 'Authorization: Bearer sk-1234' \
-H 'Content-Type: application/json' \
-d '{
"model": "gpt-4o",
"messages": [{"role": "user", "content": "Summarize the latest open PR"}],
"tools": [{
"type": "mcp",
"server_url": "litellm_proxy/mcp/github",
"server_label": "github_mcp",
"require_approval": "never"
}]
}'
{
"mcpServers": {
"LiteLLM": {
"url": "http://localhost:4000/mcp/",
"headers": {
"x-litellm-api-key": "Bearer sk-1234"
}
}
}
}
https://docs.litellm.ai/docs/mcp
| 提供商 | /chat/completions | /messages | /responses | /embeddings | /image/generations | /audio/transcriptions | /audio/speech | /moderations | /batches | /rerank |
|---|---|---|---|---|---|---|---|---|---|---|
| https://docs.litellm.ai/docs/providers/abliteration | ✅ | |||||||||
| https://docs.litellm.ai/docs/providers/aiml | ✅ | ✅ | ✅ | ✅ | ✅ | |||||
| https://docs.litellm.ai/docs/providers/ai21 | ✅ | ✅ | ✅ | |||||||
| https://docs.litellm.ai/docs/providers/ai21 | ✅ | ✅ | ✅ | |||||||
| https://docs.litellm.ai/docs/providers/aleph_alpha | ✅ | ✅ | ✅ | |||||||
| https://docs.litellm.ai/docs/providers/amazon_nova | ✅ | ✅ | ✅ | |||||||
| https://docs.litellm.ai/docs/providers/anthropic | ✅ | ✅ | ✅ | ✅ | ||||||
| https://docs.litellm.ai/docs/providers/anthropic | ✅ | ✅ | ✅ | ✅ | ||||||
| https://docs.litellm.ai/docs/providers/anyscale | ✅ | ✅ | ✅ | |||||||
| https://docs.litellm.ai/docs/pass_through/assembly_ai | ✅ | ✅ | ✅ | ✅ | ||||||
| https://docs.litellm.ai/docs/proxy/auto_routing | ✅ | ✅ | ✅ | |||||||
| https://docs.litellm.ai/docs/providers/bedrock | ✅ | ✅ | ✅ | ✅ | ✅ | |||||
| https://docs.litellm.ai/docs/providers/aws_sagemaker | ✅ | ✅ | ✅ | ✅ | ||||||
| https://docs.litellm.ai/docs/providers/azure | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | |
| https://docs.litellm.ai/docs/providers/azure_ai | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | |
| https://docs.litellm.ai/docs/providers/azure | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | |||
| https://docs.litellm.ai/docs/providers/baseten | ✅ | ✅ | ✅ | |||||||
| https://docs.litellm.ai/docs/providers/bytez | ✅ | ✅ | ✅ | |||||||
| https://docs.litellm.ai/docs/providers/cerebras | ✅ | ✅ | ✅ | |||||||
| https://docs.litellm.ai/docs/providers/clarifai | ✅ | ✅ | ✅ | |||||||
| https://docs.litellm.ai/docs/providers/cloudflare_workers | ✅ | ✅ | ✅ | |||||||
| https://docs.litellm.ai/docs/providers/codestral | ✅ | ✅ | ✅ | |||||||
| https://docs.litellm.ai/docs/providers/cognition | ✅ | ✅ | ✅ | |||||||
| https://docs.litellm.ai/docs/providers/cohere | ✅ | ✅ | ✅ | ✅ | ✅ | |||||
| https://docs.litellm.ai/docs/providers/cohere | ✅ | ✅ | ✅ | |||||||
| https://docs.litellm.ai/docs/providers/cometapi | ✅ | ✅ | ✅ | ✅ | ||||||
| https://docs.litellm.ai/docs/providers/compactifai | ✅ | ✅ | ✅ | |||||||
| https://docs.litellm.ai/docs/providers/custom_llm_server | ✅ | ✅ | ✅ | |||||||
| https://docs.litellm.ai/docs/providers/openai_compatible | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | |||
| https://docs.litellm.ai/docs/providers/dashscope | ✅ | ✅ | ✅ | ✅ | ✅ | |||||
| https://docs.litellm.ai/docs/providers/databricks | ✅ | ✅ | ✅ | |||||||
| https://docs.litellm.ai/docs/providers/datarobot | ✅ | ✅ | ✅ | |||||||
| https://docs.litellm.ai/docs/providers/deepgram | ✅ | ✅ | ✅ | ✅ | ||||||
| https://docs.litellm.ai/docs/providers/deepinfra | ✅ | ✅ | ✅ | |||||||
| https://docs.litellm.ai/docs/providers/deepseek | ✅ | ✅ | ✅ | |||||||
| https://docs.litellm.ai/docs/providers/elevenlabs | ✅ | ✅ | ✅ | ✅ | ✅ | |||||
| https://docs.litellm.ai/docs/providers/empower | ✅ | ✅ | ✅ | |||||||
| https://docs.litellm.ai/docs/providers/fal_ai | ✅ | ✅ | ✅ | ✅ | ||||||
| https://docs.litellm.ai/docs/providers/featherless_ai | ✅ | ✅ | ✅ | |||||||
| https://docs.litellm.ai/docs/providers/fireworks_ai | ✅ | ✅ | ✅ | |||||||
| https://docs.litellm.ai/docs/providers/friendliai | ✅ | ✅ | ✅ | |||||||
| https://docs.litellm.ai/docs/providers/galadriel | ✅ | ✅ | ✅ | |||||||
| https://docs.litellm.ai/docs/providers/github_copilot | ✅ | ✅ | ✅ | ✅ | ||||||
| https://docs.litellm.ai/docs/providers/github | ✅ | ✅ | ✅ | |||||||
| https://docs.litellm.ai/docs/providers/palm | ✅ | ✅ | ✅ | |||||||
| https://docs.litellm.ai/docs/providers/vertex | ✅ | ✅ | ✅ | ✅ | ✅ | |||||
| https://docs.litellm.ai/docs/providers/gemini | ✅ | ✅ | ✅ | |||||||
| https://docs.litellm.ai/docs/providers/gradient_ai | ✅ | ✅ | ✅ | |||||||
| https://docs.litellm.ai/docs/providers/groq | ✅ | ✅ | ✅ | |||||||
| https://docs.litellm.ai/docs/providers/heroku | ✅ | ✅ | ✅ | |||||||
| https://docs.litellm.ai/docs/providers/vllm | ✅ | ✅ | ✅ | |||||||
| https://docs.litellm.ai/docs/providers/huggingface | ✅ | ✅ | ✅ | ✅ | ✅ | |||||
| https://docs.litellm.ai/docs/providers/hyperbolic | ✅ | ✅ | ✅ | |||||||
| https://docs.litellm.ai/docs/providers/watsonx | ✅ | ✅ | ✅ | ✅ | ||||||
| https://docs.litellm.ai/docs/providers/infinity | ✅ | |||||||||
| https://docs.litellm.ai/docs/providers/jina_ai | ✅ | |||||||||
| https://docs.litellm.ai/docs/providers/lambda_ai | ✅ | ✅ | ✅ | |||||||
| https://docs.litellm.ai/docs/providers/lemonade | ✅ | ✅ | ✅ | |||||||
| https://docs.litellm.ai/docs/providers/litellm_proxy | ✅ | ✅ | ✅ | ✅ | ✅ | |||||
| https://docs.litellm.ai/docs/providers/llamafile | ✅ | ✅ | ✅ | |||||||
| https://docs.litellm.ai/docs/providers/lm_studio | ✅ | ✅ | ✅ | |||||||
| https://registry.terraform.io/namespaces/BerriAI — 无需身份验证。 |
AWS — ECS Fargate + Aurora + ElastiCache + ALB
git clone https://github.com/BerriAI/litellm.git
cd litellm/terraform/litellm/aws/examples/default
cp terraform.tfvars.example terraform.tfvars # 编辑区域/租户/环境
terraform init && terraform apply
https://registry.terraform.io/modules/BerriAI/litellm/aws/latest
或者从您自己的根配置中调用模块:
# main.tf
terraform {
required_version = ">= 1.6.0"
required_providers {
aws = { source = "hashicorp/aws", version = "~> 5.60" }
}
}
provider "aws" {
region = "us-west-2"
}
module "litellm" {
source = "BerriAI/litellm/aws"
version = "~> 1.89"
region = "us-west-2"
azs = ["us-west-2a", "us-west-2b"]
tenant = "acme"
env = "prod"
# 生产环境:提供ACM证书。如果没有,设置allow_plaintext_alb = true(仅开发/试用环境)。
# acm_certificate_arn = "arn:aws:acm:us-west-2:111122223333:certificate/..."
allow_plaintext_alb = true
}
output "litellm_url" {
value = module.litellm.alb_dns_name
}
terraform init
terraform apply
提供商 API 密钥存储在 AWS Secrets Manager 中;通过gateway_extra_secrets引用 ARN。完整输入列表和架构图请参见https://registry.terraform.io/modules/BerriAI/litellm/aws/latest?tab=inputs。
GCP — Cloud Run + Cloud SQL + Memorystore + HTTPS LB
真正的一键部署。打开 Cloud Shell,克隆此仓库,并通过内置的DeployStack教程引导您完成terraform apply — 选择项目,教程会设置 Artifact Registry 远程仓库,根据您的回答编写terraform.tfvars,并运行 apply。
https://registry.terraform.io/modules/BerriAI/litellm/google/latest
如果要从您自己的配置中调用模块,由于 Cloud Run 无法直接从ghcr.io拉取镜像,需先设置一个由 GHCR 支持的一次性 Artifact Registry 远程仓库:
gcloud artifacts repositories create litellm \
--location=us-central1 \
--repository-format=docker \
--mode=remote-repository \
--remote-docker-repo=https://ghcr.io \
--project=my-gcp-project
然后:
# main.tf
terraform {
required_version = ">= 1.6.0"
required_providers {
google = { source = "hashicorp/google", version = "~> 6.10" }
google-beta = { source = "hashicorp/google-beta", version = "~> 6.10" }
}
}
provider "google" { project = "my-gcp-project"; region = "us-central1" }
provider "google-beta" { project = "my-gcp-project"; region = "us-central1" }
module "litellm" {
source = "BerriAI/litellm/google"
version = "~> 1.89"
project_id = "my-gcp-project"
region = "us-central1"
tenant = "acme"
env = "prod"
# 将my-gcp-project替换为您的GCP项目ID(与上面的project_id值相同)。
image_registry = "us-central1-docker.pkg.dev/my-gcp-project/litellm/berriai"
# 生产环境:提供已指向LB IP的DNS以使用Google托管证书。
# 如果没有,设置allow_plaintext_lb = true(仅开发/试用环境)。
# lb_domains = ["proxy.example.com"]
allow_plaintext_lb = true
}
output "litellm_url" {
value = module.litellm.load_balancer_url
}
terraform init
terraform apply
提供商 API 密钥存储在 Secret Manager 中;通过gateway_extra_secrets引用资源 ID(例如projects/my-gcp-project/secrets/openai-api-key)。完整输入列表和架构图请参见https://registry.terraform.io/modules/BerriAI/litellm/google/latest?tab=inputs。
两个堆栈均包含
LITELLM_MASTER_KEYprisma migrate deployproxy_config配置项 — 以类型化映射形式传入 YAMLTerraform 模块位于此仓库的terraform/litellm/aws/和terraform/litellm/gcp/;注册表条目是只读镜像,每次发布时更新。
服务
docker-compose up db prometheus后端
make bootstrapuv run python litellm/proxy/proxy_cli.py前端
ui/litellm-dashboard(依赖项已通过make bootstrap安装)npm run devcosign verify \
--key https://raw.githubusercontent.com/BerriAI/litellm/0112e53046018d726492c814b3644b7d376029d0/cosign.pub \
ghcr.io/berriai/litellm:
使用发布标签验证(便捷方式):
本仓库中的标签受到保护,且解析为相同的密钥。此选项更易读,但依赖于标签保护规则:
cosign verify \
--key https://raw.githubusercontent.com/BerriAI/litellm/ /cosign.pub \
ghcr.io/berriai/litellm:
将 替换为您要部署的版本(例如 v1.83.0-stable)。
适用于需要更优安全性、用户管理和专业支持的企业
https://litellm.ai/enterprise https://enterprise.litellm.ai/demo
包含以下内容:
我们欢迎对 LiteLLM 做出贡献!无论是修复漏洞、添加功能还是改进文档,我们都感谢您的帮助。
这需要安装 uv。
git clone https://github.com/BerriAI/litellm.git
cd litellm
make install-dev # 安装开发依赖
make format # 格式化代码
make lint # 运行所有代码检查
make test-unit # 运行单元测试
make format-check # 仅检查格式
有关详细的贡献指南,请参阅 CONTRIBUTING.md。
[!NOTE] 📖 想要为文档做贡献? LiteLLM 文档已迁移至独立仓库:https://github.com/BerriAI/litellm-docs。请在该仓库提交文档 PR。文档托管于 https://docs.litellm.ai。
LiteLLM 遵循 https://google.github.io/styleguide/pyguide.html。
我们的自动化检查包括:
所有这些检查必须通过,您的 PR 才能被合并。
来自真实用户的反馈,见证轩辕镜像的优质服务