Source: https://aiprimetech.io/zh/learn/use-claude-api-with-litellm/ [首页](/zh/) / [学习](/zh/learn/) / 将 LiteLLM 路由到 Claude # 通过 LiteLLM 路由到 Claude 许多团队将 LiteLLM 作为所有服务前面的代理层,为全部应用提供统一的 OpenAI 兼容 API。将其 model_list 指向 AI Prime Tech,这个端点就能访问 Claude,还能通过同一个多模型网关访问 GPT 和 Gemini。 ## model_list 与提供商前缀 在 config.yaml 中,每个 model_list 条目都包含面向客户端的 model_name 和 litellm_params。model 字段包含一个提供商前缀,用于决定通信协议:anthropic/ 使用原生 Messages API,openai/ 使用 Chat Completions。 将 api_base 设置为网关地址,并通过 os.environ/ 设置 api_key。由于 AI Prime Tech 提供 OpenAI 兼容接口,使用 openai/ 并将 api_base 设置为以 /v1 结尾的地址,是最简单的接入方式。 ## URL 后缀陷阱 使用 anthropic/ 时,LiteLLM 会自动在根 api_base 后追加 /v1/messages。若要指定特殊路径,请设置 LITELLM_ANTHROPIC_DISABLE_URL_SUFFIX=true 并提供完整路径。使用 openai/ 时,请提供包含 /v1 的基础地址,LiteLLM 会追加 /chat/completions。 前缀还决定 JSON 请求体的结构,因此,如果它与网关预期的格式不匹配,就会返回 400 错误;请确保前缀与网关接口一致。 ## 以 LiteLLM 作为统一接入层 经典用法是将 LiteLLM 作为本地代理,让 Claude Code、脚本和其他工具都连接到它。你可以在 config.yaml 中切换上游模型或网关,无需逐一修改客户端,同时获得统一的日志记录、路由和回退机制。 将 AI Prime Tech 作为上游后,一个 LiteLLM 端点就能将请求分发给 Claude、GPT 和 Gemini,让整个技术栈使用统一 API,同时保留完整的模型选择空间。 ## 请求量的集中点 LiteLLM 是许多应用的汇聚点,因此承载着技术栈中最密集的请求流。这也使它成为成本可预测性最为重要的环节。 在其后接入多模型网关,就能将批量任务路由到低成本模型,将复杂任务交给 Claude,并在同一处统一计量。 复制 ``` # config.yaml model_list: - model_name: claude-sonnet-4-5 litellm_params: model: openai/claude-sonnet-4-5 api_base: https://aiprimetech.io/v1 api_key: os.environ/AIPRIME_KEY # litellm --config config.yaml ``` ## 常见问题 如何将 LiteLLM 指向 AI Prime Tech? 添加一个 model_list 条目,将 model 设置为 openai/claude-sonnet-4-5,api_base 设置为 https://aiprimetech.io/v1,,并通过 os.environ 设置 api_key。也可以使用 anthropic/,并将 api_base 设置为根地址。 使用 anthropic/ 还是 openai/ 前缀? OpenAI 兼容接口使用 openai/(基础地址包含 /v1)。anthropic/ 会向根地址 + /v1/messages 发送原生 Messages 请求。 LiteLLM 总是追加 /v1/messages,如何阻止? 设置 LITELLM_ANTHROPIC_DISABLE_URL_SUFFIX=true,并提供完整路径。 一个 LiteLLM 端点能访问多个模型吗? 可以。AI Prime Tech 支持多模型,因此 LiteLLM 可以通过同一个网关将请求路由到 Claude、GPT 和 Gemini。 几分钟内开始使用 Claude 获取 API 密钥,无需 Anthropic 账户,也无需加入候补名单。[获取你的 API 密钥](/register) AI Prime Tech 是独立的 API 网关,与 Anthropic 无关联,未获得其背书,也不是其经销商。Claude 及相关模型名称是其各自所有者的商标。 ## 更多 Claude API 指南 [如何获取 Claude API 密钥](/zh/learn/how-to-get-a-claude-api-key/)[Claude API 定价详解](/zh/learn/claude-api-pricing-explained/)[使用 Claude API 最便宜的方式](/zh/learn/cheapest-way-to-use-claude-api/)[通过 Claude API 不限量使用 Cursor](/learn/use-claude-api-with-cursor/)[不限量访问 Claude Code](/zh/learn/use-claude-api-with-claude-code/)[Claude API 网关与 Anthropic 直连对比](/zh/learn/claude-api-vs-anthropic-direct/)[通过兼容 OpenAI 的 API 使用 Claude](/zh/learn/openai-compatible-claude-api/)[Claude 模型详解:Claude Opus、Sonnet、Haiku 与 Fable 的模型对比——全部 Claude API 模型、Anthropic 模型名称与价格(2026)](/zh/learn/claude-api-models-compared/)[使用加密货币支付 Claude API 费用](/zh/learn/claude-api-with-crypto-payment/)[无需候补名单即可访问 Claude API](/zh/learn/claude-api-without-waitlist/)[如何减少 Claude 词元用量](/zh/learn/how-to-reduce-claude-token-usage/)[通过 Claude API 不限量使用 Cline](/zh/learn/use-claude-api-with-cline/)[通过 Claude API 不限量使用 Roo Code](/zh/learn/use-claude-api-with-roo-code/)[在 JetBrains IDE 中不限量使用 Claude](/zh/learn/use-claude-api-with-jetbrains/)[通过 Claude API 无限制使用 Aider](/zh/learn/use-claude-api-with-aider/)[在 VS Code 中不限量使用 Claude](/zh/learn/use-claude-api-with-vscode/)[OpenCode 的 Claude 配置:opencode.json 设置、模型与常见错误](/zh/learn/use-claude-api-with-opencode/)[在 Claude 上运行不受限制的 Hermes 智能体](/zh/learn/run-hermes-agent-with-claude-api/)[使用 Claude 不限量运行 OpenClaw](/zh/learn/run-openclaw-with-claude-api/)[兼容 Anthropic 的 API 意味着什么](/zh/learn/anthropic-compatible-api/)[Claude Code API 密钥 — ANTHROPIC_API_KEY:如何获取、配置,以及何时应改用 claude setup-token](/zh/learn/claude-code-api-key-setup/)[Claude Code API 成本 — 定价与降低成本的方法](/zh/learn/claude-code-api-costs/)[Claude API 错误详解:服务器错误 500、过载 529、速率限制 429、错误请求 400 — 以及各自的修复方法](/zh/learn/claude-api-errors-troubleshooting/)[如何购买 Claude API 额度,以及为什么购买 Claude 额度比任何“购买 Claude 账户”的方案都更好](/zh/learn/buy-claude-api-credits/)[Claude 免费 API:有免费的 Claude API 密钥吗?2026 年究竟有哪些内容免费?](/zh/learn/claude-api-free-trial/)[Claude API 与 Claude Pro/Max 订阅——如何选择](/zh/learn/claude-api-vs-subscription/)[使用 Claude 运行 Codex CLI](/zh/learn/use-claude-api-with-codex/)[将 Claude 连接到 n8n](/zh/learn/use-claude-api-with-n8n/)[在 Kilo Code 中使用 Claude](/zh/learn/use-claude-api-with-kilo-code/)[将 Claude 接入 GitHub Copilot](/zh/learn/use-claude-api-with-github-copilot/)[通过网关将 Zed 连接到 Claude](/zh/learn/use-claude-api-with-zed/)[将 Cherry Studio 连接到 Claude](/zh/learn/use-claude-api-with-cherry-studio/)[LangChain 中的 ChatAnthropic:导入、base_url、流式传输、工具和错误](/zh/learn/use-claude-api-with-langchain/)[Anthropic Python SDK:安装、设置 base_url、流式传输和错误处理](/zh/learn/anthropic-python-sdk/)[通过 Vercel AI SDK 使用 Claude:createAnthropic baseURL、流式传输和问题修复](/zh/learn/use-claude-api-with-vercel-ai-sdk/)[使用 Claude 运行 Factory Droid](/zh/learn/use-claude-api-with-factory-droid/)[Claude Code API 详解](/zh/learn/claude-code-api/)[将 Claude API 集成到您的应用中](/zh/learn/claude-api-integration/)[如何不受限制地使用 Claude,以及为什么不存在“Claude Code 破解版本”](/zh/learn/get-unlimited-claude-usage/)