创建消息
试用版

发布 https://api.openai.com/v1/threads/{thread_id}/messages

创建消息。source

路径参数

要为其创建消息的线程的 ID。source

请求正文

创建消息的实体的角色。允许的值包括:source

  • user:表示消息是由实际用户发送的,在大多数情况下应该用于表示用户生成的消息。
  • assistant:表示消息由助手生成。使用此值可将来自助手的消息插入到对话中。

附加到邮件的文件列表,以及应将它们添加到的工具。source

一组 16 个可附加到对象的键值对。这对于以结构化格式存储有关对象的其他信息非常有用。键的长度最大为 64 个字符,值的长度最大为 512 个字符。source

返回

消息对象。source

示例请求
1
2
3
4
5
6
7
8
curl https://api.openai.com/v1/threads/thread_abc123/messages \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "OpenAI-Beta: assistants=v2" \
  -d '{
      "role": "user",
      "content": "How does AI work? Explain it in simple terms."
    }'
响应
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
{
  "id": "msg_abc123",
  "object": "thread.message",
  "created_at": 1713226573,
  "assistant_id": null,
  "thread_id": "thread_abc123",
  "run_id": null,
  "role": "user",
  "content": [
    {
      "type": "text",
      "text": {
        "value": "How does AI work? Explain it in simple terms.",
        "annotations": []
      }
    }
  ],
  "attachments": [],
  "metadata": {}
}