BUZZ AI Gateway
文档 · API 参考 · POST /v1/chat/completions

Chat Completions

使用 OpenAI 兼容协议创建 chat completion。同一接口可调用 OpenAI、Claude、Gemini、Qwen、DeepSeek 等多种后端 — BUZZ 根据 model 字段路由上游,必要时自动完成协议转换。

POST https://buzzai.cc/v1/chat/completions
OpenAI 即插即用兼容。 已经在调用 https://api.openai.com/v1/chat/completions 的代码,只需替换 base URL 和 API key。OpenAI 官方 35 个请求字段全部接受,包括 toolsresponse_formatweb_search_optionsreasoning_effortstream_optionsverbosityPOST /v1/completions 也走同一 OpenAI 格式。

鉴权

BUZZ 接受标准的 OpenAI bearer token 鉴权:

Header说明
Authorization: Bearer <KEY>推荐。OpenAI SDK 默认约定。
Authorization: Bearer sk-<KEY>sk- 前缀会被自动剥离。

Anthropic 风格的 x-api-key/v1/messages/v1/models 路径上生效;/v1/chat/completions 请使用 Authorization: Bearer

Authorization: Bearer <YOUR_BUZZ_KEY>
Content-Type: application/json

请求示例

curl -X POST https://buzzai.cc/v1/chat/completions \
  -H "Authorization: Bearer $BUZZ_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-haiku-4-5-20251001",
    "messages": [
      {"role": "user", "content": "reply with exactly: hello world"}
    ],
    "max_tokens": 32
  }'
from openai import OpenAI

client = OpenAI(
    base_url="https://buzzai.cc/v1",
    api_key="",
)

resp = client.chat.completions.create(
    model="claude-haiku-4-5-20251001",
    messages=[
        {"role": "user", "content": "reply with exactly: hello world"}
    ],
    max_tokens=32,
)

print(resp.choices[0].message.content)
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://buzzai.cc/v1",
  apiKey: process.env.BUZZ_API_KEY,
});

const resp = await client.chat.completions.create({
  model: "claude-haiku-4-5-20251001",
  messages: [
    { role: "user", content: "reply with exactly: hello world" },
  ],
  max_tokens: 32,
});

console.log(resp.choices[0].message.content);

响应

{
  "id": "chatcmpl-AbCdEf...",
  "object": "chat.completion",
  "created": 1748246400,
  "model": "claude-haiku-4-5-20251001",
  "choices": [
    {
      "index": 0,
      "message": {"role": "assistant", "content": "hello world"},
      "logprobs": null,
      "finish_reason": "stop"
    }
  ],
  "usage": {"prompt_tokens": 14, "completion_tokens": 2, "total_tokens": 16}
}

请求体参数

BUZZ 接受 OpenAI CreateChatCompletionRequest 定义的所有字段。下表列出 35 个官方字段以及 top_k(非官方,但 Claude / Gemini / Qwen 等多个后端常用)。

核心字段

字段类型说明
model必填string使用的模型。从 GET /v1/models 拉取实时列表。
messages必填array对话轮次。Role 取值:system / developer / user / assistant / tool。非空。
max_tokensinteger最大输出 token 数。OpenAI 已弃用,但仍接受。
max_completion_tokensinteger新版 token 上限,亦覆盖 reasoning token。
streambooleantrue 时返回 Server-Sent Events 流。默认 false
stream_optionsobject{"include_usage": true} 在最后一个 chunk 输出 usage。
ninteger生成数量,1..128。默认 1。
stopstring | array最多 4 个停止序列。

采样

字段类型说明
temperaturenumber采样温度,0..2,默认 1。
top_pnumberNucleus 采样,0..1,默认 1。和 temperature 二选一。
top_kinteger非 OpenAI 官方扩展;支持的后端(Claude、Gemini、Qwen)会原样接收。
seedinteger尽力保持确定性。OpenAI 处于 beta 状态。
presence_penaltynumber-2..2,默认 0。
frequency_penaltynumber-2..2,默认 0。
logit_biasobjecttoken id → bias(-100..100)。
logprobsboolean返回 token 对数概率,默认 false
top_logprobsinteger0..20,需 logprobs: true

工具与结构化输出

字段类型说明
toolsarrayFunction 或 custom 工具定义。详见 Tool Use
tool_choicestring | object"auto""required""none",或 {"type":"function","function":{"name":"..."}}
parallel_tool_callsboolean允许一轮内并行调用多个工具。
response_formatobject{"type":"text"}{"type":"json_object"},或 {"type":"json_schema","json_schema":{...}}
function_callstring | object已弃用。Tools API 之前的格式;仍接受。
functionsarray已弃用,改用 tools
predictionobject预测输出,用于加速重写型生成。

推理与多模态

字段类型说明
reasoning_effortstringminimal / low / medium / high。在 Claude 路径下,BUZZ 把 low/medium/high 映射为 thinking.budget_tokens 1280 / 2048 / 4096。
verbositystringGPT-5 系列的输出冗余度:low / medium / high
modalitiesarray输出模态,如 ["text"]["text","audio"]
audioobject{"voice":"...","format":"..."},音频输出配置。
web_search_optionsobject原生联网检索提示。search_context_size 取值 low/medium/high(默认 medium)。Claude 路径下转为 web_search_20250305 工具,max_uses 对应 1 / 5 / 10。

缓存、计费与身份

字段类型说明
prompt_cache_keystring路由提示,用于提升 prompt-cache 命中率。
prompt_cache_retentionstringin_memory24h
storeboolean是否在上游存储请求/响应。默认透传;通道可通过 disable_store 关闭。
metadataobject自由形式的字符串映射。
userstring已弃用的终端用户标识。
safety_identifierstring默认被过滤。见下方说明。
service_tierstring默认被过滤。见下方说明。
通道级开关字段。以下 6 个字段会被 BUZZ 在转发前从请求体里剔除,除非通道开启对应 allow flag:service_tiersafety_identifierstream_options.include_obfuscation,以及 Claude 专属的 inference_geospeedstore 默认透传,但通道可单独关闭。若通道或网关启用 pass-through 模式,则跳过过滤、原样透传。

当 model 是 Claude 模型时

同一 /v1/chat/completions 端点也可以指向 Claude 模型(如 claude-haiku-4-5-20251001claude-sonnet-4-6claude-opus-4-7)。BUZZ 会把请求改写为 Anthropic Messages API、把响应转回 OpenAI 格式 — 但若干 OpenAI 独有字段在 Anthropic 协议里没有等价物,会被静默丢弃

Claude 路径下被静默丢弃的字段

Claude 请求构造器不会把这些字段塞进出站 payload,显式传也无效。请预先规避:

字段对 Claude 的影响
n恒为单条结果,n > 1 不支持。
presence_penalty丢弃。
frequency_penalty丢弃。
logit_bias丢弃。
logprobs / top_logprobs丢弃。响应中 logprobs 永为 null
seed丢弃。
response_format丢弃。JSON 模式 / JSON-Schema 强制不会传到 Claude。需要时改用 prompt-engineered JSON 或调用 GPT 模型。
function_call / functions丢弃(请改用现代 tools)。
prediction / modalities / audio丢弃。
verbosity丢弃。
user / safety_identifier丢弃。
prompt_cache_key丢弃。
metadata丢弃。
service_tier / store丢弃。

Claude 上的采样覆盖

Claude 模型在思考模式下,或者模型为 opus-4-7 时,采样参数会被 BUZZ 在出站前覆盖:

字段映射

OpenAI 输入Claude 表达
role 为 system 的 messages抽取到 Claude 顶层 system: [{type:"text",...}]
tools / tool_choice / parallel_tool_calls转为 Anthropic tools,字段为 name / description / input_schema
image_url / input_audio / file / video_url 内容块由网关拉取并转码为 Claude base64 image / document
stop(字符串或数组)stop_sequences 数组
max_tokens / max_completion_tokens取较大值,落到 Claude max_tokens
web_search_optionsweb_search_20250305 工具,max_uses 1 / 5 / 10
reasoning_effortthinking.budget_tokens 1280 / 2048 / 4096
reasoning(OpenRouter 风格)解析后,reasoning.max_tokens 覆盖 thinking budget

响应

非流式响应遵循 OpenAI chat.completion 标准格式。

字段类型说明
idstringOpenAI:chatcmpl-...。Claude:直接复用上游 msg_...
objectstring恒为 "chat.completion"
createdintegerUnix 时间戳。
modelstring上游实际使用的模型,可能是带日期的别名。
choices[].indexinteger从 0 起的 choice 序号。
choices[].message.rolestring恒为 "assistant"
choices[].message.contentstring | null拼接后的文本。仅返回 tool call 时为 null。
choices[].message.tool_callsarray函数工具调用;Claude 路径下从 tool_use 块构造。
choices[].message.reasoning_contentstringBUZZ 扩展。o-系列、gpt-5 thinking、Claude thinking 块下生成。
choices[].finish_reasonstringstop / length / tool_calls / content_filter / function_call。Claude 映射:end_turn→stopmax_tokens→lengthtool_use→tool_callsrefusal→content_filter
choices[].logprobsobject | nullOpenAI 透传;Claude 永为 null。
system_fingerprintstring仅当上游返回时透传。Claude 响应永不出现。
service_tierstring | nullOpenAI 透传;Claude 不返回。
usageobjectToken 计数(见下)。

usage 子字段

OpenAI 字段原样返回。BUZZ 增加若干扩展字段,用于缓存与推理可观测性。

字段说明
prompt_tokens输入 token 数(Claude 路径下为 input_tokens + cached_tokens + cached_creation_tokens 合计)。
completion_tokens输出 token 数。
total_tokensprompt_tokens + completion_tokens
prompt_tokens_details{cached_tokens, cached_creation_tokens, text_tokens, audio_tokens, image_tokens}
completion_tokens_details{text_tokens, audio_tokens, image_tokens, reasoning_tokens}
prompt_cache_hit_tokensBUZZ 扩展。缓存命中 token 的便捷标量。
input_tokens / output_tokensBUZZ 扩展。Anthropic 风格的别名,方便跨协议消费。
claude_cache_creation_5m_tokens / _1h_tokensBUZZ 扩展。拆分 Claude 1 小时缓存。
usage_semantic / usage_sourceBUZZ 扩展。usage_source = "anthropic" 表示该次调用走的是 Claude 路径。

流式

请求体加 "stream": true 启用 Server-Sent Events 流。每个事件是一行 data: {...},以 data: [DONE] 结束。

Stream chunk 结构

{
  "id": "chatcmpl-...",
  "object": "chat.completion.chunk",
  "created": 1748246400,
  "model": "claude-haiku-4-5-20251001",
  "choices": [
    {
      "index": 0,
      "delta": {"role": "assistant", "content": "Hello"},
      "logprobs": null,
      "finish_reason": null
    }
  ]
}

设置 stream_options.include_usage = true,会在最后追加一个 choices 为空、usage 已填充的 chunk。

Claude 流的转译规则

当 model 是 Claude 模型,BUZZ 把 Anthropic event: 流转为 OpenAI chunk:

Claude 事件OpenAI chunk delta
message_start首个 chunk,delta.role="assistant",delta.content=""
content_block_start(text)文本起始 chunk
content_block_start(tool_use)delta.tool_calls[].idfunction.name
content_block_delta(text_delta)delta.content 增量
content_block_delta(input_json_delta)delta.tool_calls[].function.arguments 增量
content_block_delta(thinking_delta)delta.reasoning_content 增量
content_block_delta(signature_delta)用换行符占位写入 reasoning_content(签名段不暴露明文)
message_delta设置 finish_reason(经 OpenAI 映射)
message_stop跳过;data: [DONE] 由网关补发

如何识别本次响应来自哪个上游

同一接口可命中 OpenAI 或 Claude,你不需要解析 model 名,以下信号即可指纹化判断:

信号OpenAI / GPTClaude
id 前缀chatcmpl-...msg_...
system_fingerprint上游返回时存在从不出现
choices[].logprobs请求时返回对象恒为 null
usage.usage_source"anthropic"
service_tier可能存在不返回
choices[].message.reasoning_content仅 o-系列、gpt-5 thinkingthinking 模式必有

错误码

OpenAI 风格错误包络:

{
  "error": {
    "code": "",
    "message": "Invalid token (request id: 202605260708...)",
    "type": "buzz_error"
  }
}
HTTPerror.type典型场景
400invalid_request_errorJSON 错、缺 modelmessages 为空、max_tokens 越界
401buzz_error / authentication_errorAPI key 缺失或不识别
403permission_errorKey 对该模型或 group 没权限
413request_too_large请求体超过网关上限
429rate_limit_error命中 key / 模型 / 通道级限流,遵守 retry-after
500api_error内部错误,带退避重试
503buzz_error / model_not_foundBUZZ 特有:该 model 在你的 group 下无可用通道
529overloaded_error上游过载,带较长退避

相关链接