codecamp

OpenAI 获取聊天补全消息

获取聊天消息

get /chat/completions/{completion_id}/messages

获取已存储聊天补全中的消息。仅返回创建时将store参数设为true的聊天补全。

路径参数

  • completion_id: string

查询参数

  • after: optional string

上一次分页请求中最后一条消息的标识。

  • limit: optional integer(默认 20)

要检索的消息数量。

  • order: optional "asc" or "desc"(默认 "asc")

按时间戳排列消息的顺序。asc为升序,desc为降序,默认为asc。

  • "asc"

  • "desc"

返回值

  • data: array of ChatCompletionStoreMessage

聊天补全消息对象数组。

  • id: string

  • content: string or null

  • content_parts: array of object { type, file, image_url, 2 more } or null

  • type: "text" or "image_url" or "input_audio" or "file"

  • "text"

  • "image_url"

  • "input_audio"

  • "file"

  • file: optional object { file_data, file_id, filename } or null

  • file_data: optional string or null

  • file_id: optional string or null

  • filename: optional string or null

  • image_url: optional object { url, detail } or null

  • url: string

  • detail: optional string or null

  • input_audio: optional object { data, format } or null

  • data: string

  • format: string

  • text: optional string or null

  • role: "user" or "assistant" or "tool" or 3 more

  • "user"

  • "assistant"

  • "tool"

  • "system"

  • "function"

  • "developer"

  • name: optional string or null

  • first_id: string or null

data数组中第一条聊天消息的标识。

  • has_more: boolean

是否还有更多聊天消息可供获取。

  • last_id: string or null

data数组中最后一条聊天消息的标识。

  • object: "list"(默认 "list")

对象类型,固定为“list”。

  • "list"

示例

## [中文] 发送GET请求到本节端点;替换API凭证和示例中出现的资源占位标识,本文制作不执行请求。
curl https://api.openai.com/v1/chat/completions/$COMPLETION_ID/messages \
    -H "Authorization: Bearer $OPENAI_API_KEY"

响应

中文说明:以下为原文JSON数据示例,字段名、枚举、数值及标识符保留;示例值不代表实际调用结果。

{
  "data": [
    {
      "id": "id",
      "content": "content",
      "content_parts": [
        {
          "type": "text",
          "file": {
            "file_data": "file_data",
            "file_id": "file_id",
            "filename": "filename"
          },
          "image_url": {
            "url": "url",
            "detail": "detail"
          },
          "input_audio": {
            "data": "data",
            "format": "format"
          },
          "text": "text"
        }
      ],
      "role": "user",
      "name": "name"
    }
  ],
  "first_id": "first_id",
  "has_more": true,
  "last_id": "last_id",
  "object": "list"
}

示例

## [中文] 发送GET请求到本节端点;替换API凭证和示例中出现的资源占位标识,本文制作不执行请求。
curl https://api.openai.com/v1/chat/completions/chat_abc123/messages \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "Content-Type: application/json"

响应

中文说明:以下为原文JSON数据示例,字段名、枚举、数值及标识符保留;示例值不代表实际调用结果。

代码内文字译释:

  • 写一首关于人工智能的俳句。

{
  "object": "list",
  "data": [
    {
      "id": "chatcmpl-AyPNinnUqUDYo9SAdA52NobMflmj2-0",
      "role": "user",
      "content": "write a haiku about ai",
      "name": null,
      "content_parts": null
    }
  ],
  "first_id": "chatcmpl-AyPNinnUqUDYo9SAdA52NobMflmj2-0",
  "last_id": "chatcmpl-AyPNinnUqUDYo9SAdA52NobMflmj2-0",
  "has_more": false
}
OpenAI Chat Completions 流式事件
OpenAI 列出聊天补全
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

其他能力与进阶指南

Embeddings 接口参考

审计日志接口参考

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }