跳转到主要内容
POST
/
threads
/
{threadId}
/
events
向 Thread 发送用户消息、权限决策或中断
curl --request POST \
  --url https://docs.mosoo.ai/api/v1/threads/{threadId}/events \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "events": [
    {
      "text": "Say hello from the API.",
      "type": "user_message"
    }
  ]
}
'
{
  "acceptedAt": "2023-11-07T05:31:56Z",
  "events": [
    {
      "clientRequestId": "<string>",
      "run": {
        "completedAt": "2023-11-07T05:31:56Z",
        "createdAt": "2023-11-07T05:31:56Z",
        "id": "01ARZ3NDEKTSV4RRFFQ69G5FAV",
        "startedAt": "2023-11-07T05:31:56Z",
        "updatedAt": "2023-11-07T05:31:56Z"
      }
    }
  ],
  "thread": {
    "agent_id": "01ARZ3NDEKTSV4RRFFQ69G5FAV",
    "attributed_user": {
      "id": "01ARZ3NDEKTSV4RRFFQ69G5FAV"
    },
    "client_external_ref": "<string>",
    "created_at": "2023-11-07T05:31:56Z",
    "created_by": {
      "id": "01ARZ3NDEKTSV4RRFFQ69G5FAV"
    },
    "id": "01ARZ3NDEKTSV4RRFFQ69G5FAV",
    "last_run_id": "01ARZ3NDEKTSV4RRFFQ69G5FAV",
    "source": "<unknown>",
    "title": "<string>",
    "updated_at": "2023-11-07T05:31:56Z"
  },
  "warnings": [
    {
      "code": "<string>",
      "message": "<string>"
    }
  ]
}

授权

Authorization
string
header
必填

使用 Authorization: Bearer mst_...。API token 用于识别账号,不携带 scope。

请求头

Idempotency-Key
string

用于安全重试 create-thread 和 send-events 调用的可选键。用同一个键重复提交相同请求会返回原始响应。如果原始请求仍在处理中就重复使用该键,会返回 409。

Maximum string length: 128

路径参数

threadId
string<ulid>
必填

create thread 返回的 Thread ID。v1 ID 是不带前缀的 ULID。

Pattern: ^[0-7][0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{25}$
示例:

"01J00000000000000000000009"

请求体

application/json

向 Thread 批量提交事件的请求体。

events
object[]
必填

要应用到 Thread 的有序事件列表。至少需要一个事件。

Minimum array length: 1

提交到 Thread 的单个事件。只能选择一种事件类型:发送用户消息、回答待处理的权限请求,或中断正在运行的 Run。

响应

已接受事件批次。

接受提交到 Thread 的一批事件后的结果。

acceptedAt
string<date-time>
必填

这批事件被接受处理的时间戳(RFC 3339)。

events
object[]
必填

每个事件对应的处理结果,顺序与提交的事件一致。

thread
object
必填

应用这批事件后的 Thread 状态。

warnings
object[]
必填

接受这批事件时产生的非致命警告,例如请求只被部分接受。没有警告时为空。