Chat Completions
OpenAI Chat Completions 格式接口
POST https://omini.ominiapi.top/v1/chat/completions请求和响应格式与 OpenAI Chat Completions 一致。
示例
curl https://omini.ominiapi.top/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OMINI_API_KEY" \
-d '{
"model": "模型名",
"messages": [
{ "role": "system", "content": "你是一个乐于助人的助手。" },
{ "role": "user", "content": "你好" }
]
}'流式输出
设置 "stream": true,响应以 SSE(text/event-stream)逐块返回,最后以 data: [DONE] 结束:
curl https://omini.ominiapi.top/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OMINI_API_KEY" \
-d '{
"model": "模型名",
"stream": true,
"messages": [{ "role": "user", "content": "写一首短诗" }]
}'stream = client.chat.completions.create(
model="模型名",
messages=[{"role": "user", "content": "写一首短诗"}],
stream=True,
)
for chunk in stream:
if chunk.choices and chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="")流式传输中途如果上游中断,会收到一个错误事件(type 为 upstream_interrupted),随后是 [DONE]。客户端应检查是否收到了完整的结束标记。
用 Chat Completions 调用 Claude / Gemini
model 直接填 Claude 或 Gemini 的模型名即可,平台会自动转换格式。部分模型特有的参数(例如 Claude 的缓存控制)在 Chat Completions 格式里无法表达,需要时请改用 Messages 或 Gemini 原生接口。