OpenAI(ChatGPT
  1. 聊天(Chat)
OpenAI(ChatGPT
  • 发出请求
  • 参数详情
  • 音频(Audio)
    • 创建语音
      POST
    • 创建转录
      POST
    • 创建翻译
      POST
  • 聊天(Chat)
    • Chat Completions 对象
    • Chat Completions 对象块
    • 创建 Chat Completions
      POST
    • Chat(流式返回)
      POST
    • 图像 + 文本联合输入接口
      POST
    • Chat(分析图片)
      POST
    • Chat(调用工具 / 函数)
      POST
    • Chat(生成图片)
      POST
    • Chat(修改图片)
      POST
  • 自动补全(Completions)
    • Completions 对象
    • 创建 Completions
      POST
  • 嵌入(Embeddings)
    • 嵌入对象
    • 创建嵌入
      POST
  • 图像(Images)
    • README
    • 图像对象
    • 创建图像
      POST
    • 创建图片编辑
      POST
    • 创建图像变体
      POST
  • 模型(Models)
    • 模型对象
    • 列出模型
      GET
    • 检索模型
      GET
  1. 聊天(Chat)

Chat(流式返回)

POST
https://apinew.tutujin.com/v1/chat/completions
聊天(Chat)
与 OpenAI Chat Completions API 对应,支持流式 SSE 返回。支持系统提示、上下文对话、函数调用等高级特性。

请求参数

Authorization
在 Header 添加参数
Authorization
,其值为在 Bearer 之后拼接 Token
示例:
Authorization: Bearer ********************
Header 参数
Content-Type
string 
必需
示例值:
application/json
Accept
string 
必需
示例值:
application/json
Authorization
string 
可选
示例值:
Bearer {{YOUR_API_KEY}}
Body 参数application/json
model
string 
必需
模型 ID,例如 gpt-3.5-turbo 或 gpt-4o
messages
array [object {2}] 
必需
对话消息数组。包含 system、user、assistant 等角色消息。
role
string 
必需
content
string 
必需
temperature
number 
可选
控制输出的随机性,范围 0~2
top_p
number 
可选
核采样阈值,一般和 temperature 二选一调整
n
integer 
可选
生成几个响应候选,默认是 1
stream
boolean 
可选
是否开启流式返回,默认 false
stop
string 
可选
设定模型生成停止的字符(最多 4 个)
max_tokens
integer 
可选
最大生成 token 数
presence_penalty
number 
可选
存在惩罚,鼓励探索新话题
frequency_penalty
number 
可选
频率惩罚,减少重复内容
logit_bias
object 
可选
调整特定 token 的概率,如 {"50256": -100}
user
string 
可选
最终用户唯一标识符,用于防滥用
response_format
object 
可选
设置返回格式,如 {"type":"json_object"}
seen
integer 
可选
种子值,用于生成一致性结果
tools
array [object] 
函数调用的定义
可选
tool_choice
object 
可选
控制是否/强制使用某个工具
示例
{
    "model": "gpt-3.5-turbo",
    "stream": true,
    "messages": [
        {
            "role": "system",
            "content": "You are a helpful assistant."
        },
        {
            "role": "user",
            "content": "Hello!"
        }
    ]
}

示例代码

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://apinew.tutujin.com/v1/chat/completions' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer ' \
--header 'Content-Type: application/json' \
--data-raw '{
    "model": "gpt-3.5-turbo",
    "stream": true,
    "messages": [
        {
            "role": "system",
            "content": "You are a helpful assistant."
        },
        {
            "role": "user",
            "content": "Hello!"
        }
    ]
}'

返回响应

🟢200成功
application/json
返回生成结果
Body
id
string 
可选
object
string 
可选
created
integer 
可选
choices
array [object {3}] 
可选
index
integer 
可选
message
object 
可选
finish_reason
string 
可选
usage
object 
可选
prompt_tokens
integer 
可选
completion_tokens
integer 
可选
total_tokens
integer 
可选
示例
{
    "id": "chatcmpl-123",
    "object": "chat.completion",
    "created": 1677652288,
    "choices": [
        {
            "index": 0,
            "message": {
                "role": "assistant",
                "content": "Hello there, how may I assist you today?"
            },
            "finish_reason": "stop"
        }
    ],
    "usage": {
        "prompt_tokens": 9,
        "completion_tokens": 12,
        "total_tokens": 21
    }
}
修改于 2025-05-05 13:52:06
上一页
创建 Chat Completions
下一页
图像 + 文本联合输入接口
Built with