Skip to Content

Chat Completions

OpenAI 兼容接口,URL 路径 POST https://api.inflox.ai/v1/chat/completions,适用于 OpenAI SDK 及各类 OpenAI 兼容客户端。

请求

参数类型必填说明
modelstring模型标识,格式 provider/model(也可直接填 /v1/models 返回的模型 id)
messagesarray对话消息,role 取值 system / user / assistant
streamboolean是否流式返回(默认 false
temperaturenumber采样温度(0-2,默认 1)
top_pnumber核采样(0-1,默认 1)
max_tokensinteger最大生成 token 数
stopstring / array停止序列
presence_penaltynumber存在惩罚(-2.0-2.0)
frequency_penaltynumber频率惩罚(-2.0-2.0)
seedinteger随机种子
stream_optionsobject{"include_usage": true} 时流式响应末尾携带 usage
curl https://api.inflox.ai/v1/chat/completions \ -H "Authorization: Bearer wk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" \ -H "Content-Type: application/json" \ -d '{ "model": "{provider}/{model}", "messages": [{"role": "user", "content": "Hello"}] }'

非流式响应

{ "id": "chatcmpl-...", "object": "chat.completion", "created": 1788169683, "model": "{provider}/{model}", "choices": [ { "index": 0, "message": { "role": "assistant", "content": "Hi!" }, "finish_reason": "stop" } ], "usage": { "prompt_tokens": 10, "completion_tokens": 20, "total_tokens": 30 } }

流式响应(SSE)

"stream": true 时返回 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":"Hi"},"finish_reason":null}]} data: {"id":"chatcmpl-...","object":"chat.completion.chunk","choices":[{"index":0,"delta":{},"finish_reason":"stop"}],"usage":{"prompt_tokens":10,"completion_tokens":20,"total_tokens":30}} data: [DONE]

错误响应

{ "error": { "message": "Invalid API key", "type": "authentication_error" } }

常见错误类型见 错误码

网关按模型标识路由到对应厂商的 OpenAI 兼容通道,请求中的 model 会替换为上游真实模型名。可用模型见 模型列表