POST /v1/chat/completions,与 OpenAI 的同名接口完全一致。请求体原样转发给上游模型,
所以工具调用(tools)、视觉输入、temperature、max_tokens 这些参数按你用的模型本身支持
的写就行。
curl https://bothub-api.bookab.info/v1/chat/completions \
-H "Authorization: Bearer $BOTHUB_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-5.4",
"messages": [
{"role": "system", "content": "你是一个简洁的助手。"},
{"role": "user", "content": "用一句话解释什么是向量数据库"}
]
}'
带 "stream": true 就是标准的 SSE:
stream = client.chat.completions.create(
model="gpt-5.4",
messages=[{"role": "user", "content": "写一首短诗"}],
stream=True,
)
for chunk in stream:
print(chunk.choices[0].delta.content or "", end="")
usage)会在最后一个数据块带上,不需要你自己加
stream_options——服务端会补。模型支持的话,按 OpenAI 的格式传图即可:
{
"model": "gpt-5.4",
"messages": [{
"role": "user",
"content": [
{"type": "text", "text": "这张图里有什么?"},
{"type": "image_url", "image_url": {"url": "https://example.com/cat.jpg"}}
]
}]
}
图片地址必须是上游能直接读到的:公网 URL 或 data: URI。本地文件路径不行。
单个请求最多 500 条消息。一个反复调用工具的长会话很容易超过它——这时候要自己做历史压缩,
而不是一直往后追加。超限会返回 400,message 里会写明是哪个字段。
POST /v1/responses,OpenAI 的新版协议。用 input 代替 messages:
curl https://bothub-api.bookab.info/v1/responses \
-H "Authorization: Bearer $BOTHUB_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model": "gpt-5.4", "input": "你好"}'
store: false——我们不让上游厂商持久化你的 prompt。POST /v1/embeddings,input 可以是一个字符串,也可以是最多 256 个字符串的数组。
curl https://bothub-api.bookab.info/v1/embeddings \
-H "Authorization: Bearer $BOTHUB_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "text-embedding-4",
"input": ["第一段文本", "第二段文本"]
}'
支持 dimensions 和 encoding_format(float 或 base64),按模型本身的能力传。