工具接入
在 LiteLLM 中使用 Claude API
LiteLLM 原生支持 Anthropic,并允许为每个模型覆盖端点——一行配置即可把你全部的 Claude 流量送经折扣网关。
·
直接 SDK 调用
import litellm
response = litellm.completion(
model="anthropic/claude-opus-4-8",
api_base="https://api.apitoken.sale",
api_key="sk-pool-•••",
messages=[{"role": "user", "content": "Hello"}],
)LiteLLM 代理配置
# config.yaml
model_list:
- model_name: claude-opus-4-8
litellm_params:
model: anthropic/claude-opus-4-8
api_base: https://api.apitoken.sale
api_key: sk-pool-•••用这份配置运行代理,你的 LiteLLM 网关的每个客户端都会透明地使用折扣版 Claude 端点——当多个服务共享一个路由层时尤其方便。
为什么在这里通过 LiteLLM 路由 Claude
- 在一个地方把所有服务切到更便宜的端点。
- 沿用你已有的 anthropic/ 模型前缀和参数。
- apitoken.sale 控制台按密钥追踪消费,精确到 token。
常见问题
LiteLLM 支持自定义 Anthropic api_base 吗?
支持——在 litellm.completion() 或代理配置的 litellm_params 中传入 api_base,LiteLLM 就会把 Anthropic 格式的请求发送到 https://api.apitoken.sale。
模型还用 anthropic/ 前缀吗?
是的。使用 anthropic/claude-opus-4-8(或任何受支持的模型),让 LiteLLM 应用 Anthropic 协议;变的只有端点和密钥。
基于 LiteLLM 的工具也适用吗?
适用——凡是经 LiteLLM 路由的东西(包括许多编码智能体)都会从同一份配置继承折扣端点。