运行步骤
Beta
表示在运行期间采取的步骤(模型和工具调用)。
相关指南: 助理
列出运行步骤
Beta
GET https://api.openai.com/v1/threads/{thread_id}/runs/{run_id}/steps
返回属于一个运行的运行步骤列表。
路径参数
| 参数名 | 类型 | 必需 | 描述 | 
|---|---|---|---|
| thread_id | string | 必需 | 运行和运行步骤所属的线程的ID。 | 
| run_id | string | 必需 | 运行步骤所属运行的ID。 | 
查询参数
| 参数名 | 类型 | 可选 | 默认值 | 描述 | 
|---|---|---|---|---|
| limit | integer | 可选 | 20 | 返回对象的数量限制。限制范围为1到100,默认值为20。 | 
| order | string | 可选 | desc | 根据对象的 created_at时间戳排序。asc表示升序,desc表示降序。 | 
| after | string | 可选 | 无 | 用于分页的游标。 after是定义列表中位置的对象ID。例如,如果您进行列表请求并接收100个对象,结束为obj_foo,后续调用可以包含after=obj_foo以获取列表的下一页。 | 
| before | string | 可选 | 无 | 用于分页的游标。 before是定义列表中位置的对象ID。例如,如果您进行列表请求并接收100个对象,结束为obj_foo,后续调用可以包含before=obj_foo以获取列表的上一页。 | 
返回
返回一个运行步骤对象列表。
示例请求
curl https://api.openai.com/v1/threads/thread_abc123/runs/run_abc123/steps \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "Content-Type: application/json" \
  -H "OpenAI-Beta: assistants=v2"
响应
{
  "object": "list",
  "data": [
    {
      "id": "step_abc123",
      "object": "thread.run.step",
      "created_at": 1699063291,
      "run_id": "run_abc123",
      "assistant_id": "asst_abc123",
      "thread_id": "thread_abc123",
      "type": "message_creation",
      "status": "completed",
      "cancelled_at": null,
      "completed_at": 1699063291,
      "expired_at": null,
      "failed_at": null,
      "last_error": null,
      "step_details": {
        "type": "message_creation",
        "message_creation": {
          "message_id": "msg_abc123"
        }
      },
      "usage": {
        "prompt_tokens": 123,
        "completion_tokens": 456,
        "total_tokens": 579
      }
    }
  ],
  "first_id": "step_abc123",
  "last_id": "step_abc456",
  "has_more": false
}
获取运行步骤
Beta
 GET https://api.openai.com/v1/threads/{thread_id}/runs/{run_id}/steps/{step_id}
检索一个运行步骤。
路径参数
| 参数名 | 类型 | 必需 | 描述 | 
|---|---|---|---|
| thread_id | string | 必需 | 运行和运行步骤所属的线程的ID。 | 
| run_id | string | 必需 | 运行步骤所属运行的ID。 | 
| step_id | string | 必需 | 要检索的运行步骤的ID。 | 
返回
返回与指定ID匹配的运行步骤对象。
示例请求
curl https://api.openai.com/v1/threads/thread_abc123/runs/run_abc123/steps/step_abc123 \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "Content-Type: application/json" \
  -H "OpenAI-Beta: assistants=v2"
响应
{
  "id": "step_abc123",
  "object": "thread.run.step",
  "created_at": 1699063291,
  "run_id": "run_abc123",
  "assistant_id": "asst_abc123",
  "thread_id": "thread_abc123",
  "type": "message_creation",
  "status": "completed",
  "cancelled_at": null,
  "completed_at": 1699063291,
  "expired_at": null,
  "failed_at": null,
  "last_error": null,
  "step_details": {
    "type": "message_creation",
    "message_creation": {
      "message_id": "msg_abc123"
    }
  },
  "usage": {
    "prompt_tokens": 123,
    "completion_tokens": 456,
    "total_tokens": 579
  }
}
运行步骤对象
Beta
表示运行执行中的一步。
参数
| 参数名 | 类型 | 描述 | 
|---|---|---|
| id | string | 运行步骤的标识符,可以在API端点中引用。 | 
| object | string | 对象类型,总是 thread.run.step。 | 
| created_at | integer | 运行步骤创建时的Unix时间戳(秒)。 | 
| assistant_id | string | 与运行步骤关联的 assistant 的ID。 | 
| thread_id | string | 运行的 thread 的ID。 | 
| run_id | string | 该运行步骤所属的 run 的ID。 | 
| type | string | 运行步骤的类型,可以是 message_creation或tool_calls。 | 
| status | string | 运行步骤的状态,可以是 in_progress、cancelled、failed、completed或expired。 | 
| step_details | object | 运行步骤的详细信息。 | 
| last_error | object 或 null | 该运行步骤关联的最后一个错误。如果没有错误,则为 null。 | 
| expired_at | integer 或 null | 运行步骤过期时的Unix时间戳(秒)。如果父运行已过期,则认为步骤已过期。 | 
| cancelled_at | integer 或 null | 运行步骤被取消时的Unix时间戳(秒)。 | 
| failed_at | integer 或 null | 运行步骤失败时的Unix时间戳(秒)。 | 
| completed_at | integer 或 null | 运行步骤完成时的Unix时间戳(秒)。 | 
| metadata | map | 可以附加到对象的一组16个键值对。这对于以结构化格式存储对象的附加信息非常有用。键的最大长度为64个字符,值的最大长度为512个字符。 | 
| usage | object 或 null | 与运行步骤相关的使用统计信息。在运行步骤的状态为 in_progress时,该值为null。 | 
示例对象
{
  "id": "step_abc123",
  "object": "thread.run.step",
  "created_at": 1699063291,
  "run_id": "run_abc123",
  "assistant_id": "asst_abc123",
  "thread_id": "thread_abc123",
  "type": "message_creation",
  "status": "completed",
  "cancelled_at": null,
  "completed_at": 1699063291,
  "expired_at": null,
  "failed_at": null,
  "last_error": null,
  "step_details": {
    "type": "message_creation",
    "message_creation": {
      "message_id": "msg_abc123"
    }
  },
  "usage": {
    "prompt_tokens": 123,
    "completion_tokens": 456,
    "total_tokens": 579
  }
}