流式接口
开发环境
开发环境
POST
/v1/chat/completions
在使用 API 接口前,请先在百川 API 开放平台完成实名认证、充值、创建 APIkey 等流程,如下图所示

请求示例请求示例
Shell
JavaScript
Java
Swift
curl --location --request POST 'http://dev-cn.your-api-server.com/v1/chat/completions?members&reference&Type&_postman_listIndexKey=key&_postman_listAllowsMultipleValues' \
--data-raw '{
"model": "Baichuan2-Turbo",
"messages": [
{
"role": "user",
"content": "世界第一高峰是?"
}
],
"temperature": 0.3,
"stream": true
}'
响应示例响应示例
data:{"id":"chatcmpl-M633300APBknoaF","object":"chat.completion.chunk","created":1698205608,"model":"Baichuan2-Turbo","choices":[{"index":0,"delta":{"role":"assistant","content":"世界第一高峰是珠穆"},"finish_reason":""}]}
data:{"id":"chatcmpl-M633300APBknoaF","object":"chat.completion.chunk","created":1698205608,"model":"Baichuan2-Turbo","choices":[{"index":0,"delta":{"role":"assistant","content":"朗玛峰(Mount"},"finish_reason":""}]}
data:{"id":"chatcmpl-M633300APBknoaF","object":"chat.completion.chunk","created":1698205608,"model":"Baichuan2-Turbo","choices":[{"index":0,"delta":{"role":"assistant","content":" Everest),位于尼泊尔"},"finish_reason":""}]}
data:{"id":"chatcmpl-M633300APBknoaF","object":"chat.completion.chunk","created":1698205609,"model":"Baichuan2-Turbo","choices":[{"index":0,"delta":{"role":"assistant","content":"和中国边境,海拔高度"},"finish_reason":""}]}
data:{"id":"chatcmpl-M633300APBknoaF","object":"chat.completion.chunk","created":1698205609,"model":"Baichuan2-Turbo","choices":[{"index":0,"delta":{"role":"assistant","content":"为8,84"},"finish_reason":""}]}
data:{"id":"chatcmpl-M633300APBknoaF","object":"chat.completion.chunk","created":1698205609,"model":"Baichuan2-Turbo","choices":[{"index":0,"delta":{"role":"assistant","content":"8米。"},"finish_reason":"stop"}],"usage":{"prompt_tokens":6,"completion_tokens":29,"total_tokens":35}}
data:[DONE]
请求参数
Header 参数
Content-Type
string
响应的数据格式
示例值:
application/json
Authorization
string
必需
示例值:
Bearer $API_KEY
Body 参数application/json
返回响应
修改于 2023-12-21 06:16:30