OpenAI 兼容的对话接口。一个端点路由所有模型,ZeroFA 根据 model 将请求分发到对应上游,并统一 messages 结构、采样参数和 SSE 协议。
https://zerofa.ai/v1/chat/completionsAuthorizationstring必填Bearer sk-zerofa-xxxContent-Typestring必填application/jsonmodelstring必填claude-sonnet-4-6messagesarray必填[{"role":"user","content":"hi"}]streamboolean可选falsetemperaturenumber 0–2可选1.0top_pnumber 0–1可选1.0max_tokensinteger可选1024stopstring | string[]可选tools / tool_choicearray / string|object可选response_formatobject可选reasoning_effortstring可选mediumuserstring可选{
"model": "claude-sonnet-4-6",
"messages": [
{
"role": "user",
"content": "你好,介绍一下你自己"
}
],
"stream": false,
"temperature": 1,
"max_tokens": 1024
}按 OpenAI 格式传入 tools 与 tool_choice 即可。Claude 和 Gemini 请求会自动转换为厂商原生格式,响应再转换回 tool_calls;支持流式、非流式和多轮工具结果。
{
"model": "claude-sonnet-4-6",
"messages": [{"role": "user", "content": "北京天气怎么样?"}],
"tools": [{
"type": "function",
"function": {
"name": "get_weather",
"description": "查询某城市的实时天气",
"parameters": {
"type": "object",
"properties": {"city": {"type": "string"}},
"required": ["city"]
}
}
}],
"tool_choice": "auto"
}当模型决定调用工具时,finish_reason 为 tool_calls,并在 message.tool_calls 中返回调用信息。
"message": {
"role": "assistant",
"content": "",
"tool_calls": [{
"id": "call_abc",
"type": "function",
"function": {
"name": "get_weather",
"arguments": "{\"city\":\"北京\"}"
}
}]
}执行工具后,将结果作为 role: tool 消息并携带 tool_call_id,与上一条 assistant tool_calls 一同传回,模型即可继续回答。
messages[].content 可使用 content parts 数组,混合 text 与 image_url。图像支持 data URL 或公网 URL,Claude 和 Gemini 协议会自动转换。
{
"model": "gpt-5.4-mini",
"messages": [{
"role": "user",
"content": [
{"type": "text", "text": "这张图里有什么?"},
{"type": "image_url",
"image_url": {"url": "data:image/png;base64,..."}}
]
}]
}模型是否支持视觉,请查看模型卡片的 Vision 能力标记。
stream: true 时返回 text/event-stream。每个 chunk 使用一行 data: {...},并以 data: [DONE] 结束。
data: {"id":"chatcmpl-...","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"role":"assistant","content":"你好"},"finish_reason":null}]}
data: {"id":"chatcmpl-...","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"!"},"finish_reason":null}]}
data: {"id":"chatcmpl-...","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}
data: [DONE]所有对话模型均可使用此接口,切换模型只需修改 model。完整列表和价格见 模型广场,也可以通过 GET /v1/models 获取。
完整说明见错误码与计费。最常见的错误包括:
400 model_not_allowed — model 不存在或当前 plan 不允许402 insufficient_credits — 钱包余额不足429 rate_limited — RPM 或日额度超限,或上游服务繁忙503 upstream_unavailable — 所有上游失败(少见)idstring必填objectstring必填chat.completioncreatedinteger必填modelstring必填choicesarray必填usageobject可选{
"id": "chatcmpl-...",
"object": "chat.completion",
"created": 1715961234,
"model": "claude-sonnet-4-6",
"choices": [{
"index": 0,
"message": { "role": "assistant", "content": "你好!我是……" },
"finish_reason": "stop"
}],
"usage": {
"prompt_tokens": 12,
"completion_tokens": 64,
"total_tokens": 76
}
}用下面的示例确认请求格式与返回结构。需要在线发起请求时,点击页面顶部“调试”拉起在线运行面板。
curl https://zerofa.ai/v1/chat/completions \
-H "Authorization: Bearer sk-zerofa-xxx" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-sonnet-4-6",
"messages": [
{"role": "user", "content": "你好,介绍一下你自己"}
]
}'{
"id": "chatcmpl-...",
"object": "chat.completion",
"created": 1715961234,
"model": "claude-sonnet-4-6",
"choices": [{
"index": 0,
"message": { "role": "assistant", "content": "你好!我是……" },
"finish_reason": "stop"
}],
"usage": {
"prompt_tokens": 12,
"completion_tokens": 64,
"total_tokens": 76
}
}