Skip to content
API

OpenAI 兼容格式

POST https://relient.cfd/v1/chat/completions 兼容 OpenAI Chat Completions 接口格式,用来以 OpenAI 的请求格式调用 Claude:请求体原样转发,返回 OpenAI 格式。

这只是兼容协议,不提供 GPT 等其他厂商的模型。model 填 Claude 模型 id;请求其他模型(如 gpt-image-2)会返回 400 model_not_supported,不转发、不扣费。

非流式

# pip install openai
from openai import OpenAI

client = OpenAI(
    base_url="https://relient.cfd/v1",
    api_key="sk-ta-你的Key",
)
response = client.chat.completions.create(
    model="claude-sonnet-5-5",
    messages=[{"role": "user", "content": "你好"}],
)
print(response.choices[0].message.content)

流式输出

设置 "stream": true,按 Server-Sent Events 逐块返回,最后一行是 data: [DONE]。流式和非流式的计费完全相同。

长输出请用 "stream": true。网站经 Cloudflare 加速,单个响应最多等 125 秒才开始返回;非流式请求要等全部生成完才返回,超过 115 秒会被停止,返回 504 upstream_timeout,不收费。流式输出边生成边返回,不受这个限制,计费也完全相同。
curl https://relient.cfd/v1/chat/completions \
  -H "Authorization: Bearer $TOKENARMY_API_KEY" \
  -H "content-type: application/json" \
  -d '{
    "model": "claude-sonnet-5-5",
    "stream": true,
    "messages": [{"role": "user", "content": "你好"}]
  }'

参数

  • model:Claude 模型 id,例如 claude-sonnet-5-5。带日期后缀的 id(如 claude-haiku-4-5-20251001)也能识别。
  • messages、max_tokens、temperature、tools 等按 OpenAI 规范填写。
  • 响应里的 usage 就是计费用的 token 数。