English ← MyDocs

获取聊天消息

get /v1/compliance/apps/chats/{claude_chat_id}/messages

获取特定聊天的消息历史和文件元数据。

路径参数

  • claude_chat_id: string

    聊天 ID(带标签的 ID,例如 claude_chat_abc123)

查询参数

  • after_id: optional string

    分页游标,用于获取下一页结果(向时间更早的方向翻页)。要翻页时,请传入最近一次响应中的 last_id 值。客户端应将此值视为不透明字符串,不要尝试解析或解释其内容,因为格式可能会在不另行通知的情况下更改。

  • before_id: optional string

    分页游标,用于获取上一页结果(向时间更晚的方向翻页)。要翻页时,请传入最近一次响应中的 first_id 值。客户端应将此值视为不透明字符串,不要尝试解析或解释其内容,因为格式可能会在不另行通知的情况下更改。

  • created_at: optional object { gt, gte, lt, lte }

    • gt: optional string

      过滤在此时间之后创建的消息(RFC 3339 格式)

    • gte: optional string

      过滤在此时间或之后创建的消息(RFC 3339 格式)

    • lt: optional string

      过滤在此时间之前创建的消息(RFC 3339 格式)

    • lte: optional string

      过滤在此时间或之前创建的消息(RFC 3339 格式)

  • limit: optional number

    最大结果数(最大:1000)。省略时,完整结果集将在一个响应中返回。

  • order: optional "asc" or "desc"

    响应中消息的排序方向。asc(默认)返回最旧的在前;desc 返回最新的在前。

    • "asc"

    • "desc"

  • updated_at: optional object { gt, gte, lt, lte }

    • gt: optional string

      过滤在此时间之后更新的消息(RFC 3339 格式)

    • gte: optional string

      过滤在此时间或之后更新的消息(RFC 3339 格式)

    • lt: optional string

      过滤在此时间之前更新的消息(RFC 3339 格式)

    • lte: optional string

      过滤在此时间或之前更新的消息(RFC 3339 格式)

请求头参数

  • "x-api-key": optional string

返回值

  • id: string

    聊天 ID

  • chat_messages: array of object { id, artifacts, content, 4 more }

    按 created_at 顺序排列的聊天消息数组

    • id: string

      消息的唯一标识符,例如 'claude_chat_msg_abcd1234'

    • artifacts: array of object { id, artifact_type, title, version_id }

      助手在此消息中生成或更新的版本化文档。通过 GET /v1/compliance/apps/artifacts/{artifact_version_id}/content 下载。

      • id: string

        制品 ID,例如 'claude_artifact_abc123'

      • artifact_type: string

        类似 MIME 的制品类型,例如 'application/vnd.ant.code'

      • title: string

        制品标题

      • version_id: string

        制品版本 ID,例如 'claude_artifact_version_abc123'

    • content: array of object { text, type }

      消息中的内容块

      • text: string

        来自用户或助手的文本内容

      • type: "text"

        • "text"
    • created_at: string

      消息创建时间戳 - 对于用户:发送消息的时间;对于助手:完成最后一个内容块的时间

    • files: array of object { id, filename, mime_type }

      用户上传的二进制文件附件。通过 GET /v1/compliance/apps/chats/files/{claude_file_id}/content 下载。

      • id: string

        文件 ID

      • filename: string

        文件的显示名称

      • mime_type: string

        文件上传时的 MIME 类型(例如 'application/pdf')

    • generated_files: array of object { id, filename, mime_type }

      助手通过工具使用创建的可下载文件(例如 PDF、电子表格、演示文稿)。与 files 不同,后者是附加到消息的上传文件。通过 GET /v1/compliance/apps/chats/generated-files/{claude_gen_file_id}/content 下载。

      • id: string

        不透明的生成文件 ID,例如 'claude_gen_file_abc123'。请将其视为不透明字符串;编码可能会在不另行通知的情况下更改。

      • filename: string

        生成文件的显示名称

      • mime_type: string

        生成文件的工具报告的 MIME 类型

    • role: "assistant" or "user"

      消息发送者(用户或助手)

      • "assistant"

      • "user"

  • created_at: string

    创建时间戳

  • deleted_at: string

    如果已删除,则为删除时间戳

  • first_id: string

    当前结果集中第一条消息的不透明分页游标。在下一次请求中作为 before_id 传入以向后翻页。客户端应将此值视为不透明字符串,不要尝试解析或解释其内容,因为格式可能会在不另行通知的情况下更改。

  • has_more: boolean

    当前结果集之外是否还有更多聊天消息。在后续请求中使用 last_id 作为 after_id 以向前翻页。

  • href: string

    在 claude.ai 中查看此聊天的 URL

  • last_id: string

    当前结果集中最后一条消息的不透明分页游标。在下一次请求中作为 after_id 传入以向前翻页。客户端应将此值视为不透明字符串,不要尝试解析或解释其内容,因为格式可能会在不另行通知的情况下更改。

  • model: string

    此聊天选择的模型(例如 'claude-opus-4-7')。对于从未记录过模型的旧版聊天,可能为 null。

  • name: string

    聊天名称

  • organization_id: string

    此聊天所属的组织 ID

  • organization_uuid: string

    此聊天所属的组织 UUID

  • project_id: string

    此聊天所属的项目 ID

  • updated_at: string

    最后更新时间戳

  • user: object { id, email_address }

    用户信息

    • id: string

      用户标识符

    • email_address: string

      用户的电子邮件地址

示例

curl https://api.anthropic.com/v1/compliance/apps/chats/$CLAUDE_CHAT_ID/messages \
    -H "Authorization: Bearer $ANTHROPIC_COMPLIANCE_API_KEY"

响应

{
  "id": "claude_chat_abc123",
  "name": "Product Requirements Discussion",
  "created_at": "2025-06-07T08:09:10Z",
  "updated_at": "2025-06-07T08:09:11Z",
  "organization_id": "org_abc123",
  "organization_uuid": "abcdef0123-4567-89ab-cdef-0123456789ab",
  "project_id": "claude_proj_xyz789",
  "model": "claude-opus-4-7",
  "user": {
    "id": "user_xyz456",
    "email_address": "user@example.com"
  },
  "href": "https://claude.ai/chat/abcdef01-2345-6789-abcd-ef0123456789",
  "chat_messages": [
    {
      "id": "claude_chat_msg_abc123",
      "role": "user",
      "created_at": "2025-06-07T08:09:10Z",
      "content": [
        {
          "type": "text",
          "text": "Can you help me draft requirements for our new dashboard feature?"
        }
      ],
      "files": [
        {
          "id": "claude_file_xyz789",
          "filename": "dashboard_mockup_v1.pdf",
          "mime_type": "application/pdf"
        }
      ]
    },
    {
      "id": "claude_chat_msg_def456",
      "role": "assistant",
      "created_at": "2025-06-07T08:09:11Z",
      "content": [
        {
          "type": "text",
          "text": "I'd be happy to help you draft requirements for your dashboard feature..."
        }
      ],
      "artifacts": [
        {
          "id": "claude_artifact_abc123",
          "version_id": "claude_artifact_version_xyz789",
          "title": "Dashboard Requirements Draft",
          "artifact_type": "text/markdown"
        }
      ]
    }
  ],
  "has_more": false,
  "first_id": "eyJtc2dfdXVpZCI6ICIwZjcwYjA2Ni0uLi4ifQ==",
  "last_id": "eyJtc2dfdXVpZCI6ICJhNGUwYjE3Mi0uLi4ifQ=="
}