文档 · 接入指南
LiteLLM 接 TopxAI:代理配置和 Python SDK
用 model openai/<id> 和 api_base https://ai.topxea.com/v1 把 LiteLLM 指到 TopxAI,写在代理的 model_list 或 completion() 调用里都行。
LiteLLM 用 openai/ 前缀加 api_base 接任何 OpenAI 兼容端点,用 anthropic/ 接 Anthropic 端点。TopxAI 的文本模型都在这两条路上。
Python SDK
import litellm
reply = litellm.completion(
model="openai/claude-sonnet-5-5",
api_base="https://ai.topxea.com/v1",
api_key="sk-...",
messages=[{"role": "user", "content": "Say hello in one sentence."}],
)
print(reply.choices[0].message.content)
Claude 走 Messages 接口、带提示缓存:
reply = litellm.completion(
model="anthropic/claude-sonnet-5-5",
api_base="https://ai.topxea.com",
api_key="sk-...",
messages=[...],
)
代理 config.yaml
model_list:
- model_name: claude-sonnet-5-5
litellm_params:
model: openai/claude-sonnet-5-5
api_base: https://ai.topxea.com/v1
api_key: os.environ/TOPXAI_API_KEY
- model_name: gpt-6.1-sol
litellm_params:
model: openai/gpt-6.1-sol
api_base: https://ai.topxea.com/v1
api_key: os.environ/TOPXAI_API_KEY
- model_name: kimi-k3
litellm_params:
model: openai/kimi-k3
api_base: https://ai.topxea.com/v1
api_key: os.environ/TOPXAI_API_KEY
litellm --config config.yaml 启动;客户端用 model_name 里的名字调用代理。
费用统计
LiteLLM 按模型名算价,不知道 TopxAI 的线路。要让它的费用列和用量日志对上,在 litellm_params 里按模型页填 input_cost_per_token 和 output_cost_per_token(比如 claude-sonnet-5-5 共享池是 0.000001 和 0.000005)。
不通时
模型:claude-sonnet-5-5, gpt-6.1-sol · 模型与价格
相关
- 接入你的 SDK
- 创建 API 密钥并选择线路
- curl 能跑通,工具里却报错
- 常见错误响应
- LangChain 接 TopxAI:带 base URL 的 ChatOpenAI 和 ChatAnthropic
- Vercel AI SDK 接 TopxAI:createOpenAI、createAnthropic 和 openai-compatible
- Claude Sonnet 5.5 API pricing
- GPT-6.1 Sol API pricing
上一页:Vercel AI SDK 接 TopxAI:createOpenAI、createAnthropic 和 openai-compatible · 下一页:Dify 接 TopxAI:OpenAI-API-compatible 供应商
其他语言:English