聊天接口(通用)
POST
https://api.chatgptsb.com/v1/chat/completions
注意:OpenAI、Claude、Gemini...等聊天模型均使用该接口格式。
请求参数
Header 参数
Content-Type
string
必需
示例值:
application/json
Authorization
string
令牌KEY
示例值:
Bearer sk-xxxx
Body 参数application/json
model
string
模型名称
messages
array [object {2}]
必需
role
string
角色 system | user
content
string
提问消息
temperature
integer
温度
top_p
但不是两者同时使用。top_p
integer
可选
temperature
但不是两者同时使用。max_tokens
number
最大回复
stream
boolean
流式输出
n
number
可选
presence_penalty
integer
可选
frequency_penalty
integer
可选
logit_bias
null
可选
user
string
可选
示例
{
"model": "gpt-4o",
"messages": [
{
"role": "user",
"content": "晚上好"
}
],
"max_tokens": 1688,
"temperature": 0.5,
"stream": false
}
示例代码
Shell
JavaScript
Java
Swift
Go
PHP
Python
HTTP
C
C#
Objective-C
Ruby
OCaml
Dart
R
请求示例请求示例
Shell
JavaScript
Java
Swift
curl --location --request POST 'https://api.chatgptsb.com/v1/chat/completions' \
--header 'Authorization: Bearer sk-xxxx' \
--header 'Content-Type: application/json' \
--data-raw '{
"model": "gpt-4o",
"messages": [
{
"role": "user",
"content": "晚上好"
}
],
"max_tokens": 1688,
"temperature": 0.5,
"stream": false
}'
返回响应
🟢200成功
application/json
Body
id
string
必需
object
string
必需
created
integer
必需
model
string
必需
choices
array [object {4}]
必需
index
integer
可选
message
object
可选
logprobs
null
可选
finish_reason
string
可选
usage
object
必需
prompt_tokens
integer
必需
completion_tokens
integer
必需
total_tokens
integer
必需
system_fingerprint
string
必需
示例
{
"id": "chatcmpl-A1iMgDLzZtUJ9QDpfqDLxKH0zfUnp",
"object": "chat.completion",
"created": 1724972230,
"model": "gpt-4o-2024-05-13",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "晚上好!有什么我可以帮你的吗?",
"refusal": null
},
"logprobs": null,
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 9,
"completion_tokens": 10,
"total_tokens": 19
},
"system_fingerprint": "fp_157b3831f5"
}
修改于 2024-11-23 16:24:27