---
title: Runs API 參考
description: Platform API v1 的 Runs：每個操作的路徑、參數、請求與回應欄位、scope、冪等與錯誤，直接取自 API 合約。
url: https://agentlab.cresclab.com/docs/zh-tw/api/runs
language: zh-Hant
updated: 2026-12-05
---

# Runs API 參考

Platform API v1 的 Runs：每個操作的路徑、參數、請求與回應欄位、scope、冪等與錯誤，直接取自 API 合約。

> [!NOTE]
> 由 API 合約（Agent Lab Platform API 1.0.0-alpha.1）產生。說明文字是合約的英文原文。

An application runs an agent configuration it passes with each run, for the member it acts
for. The platform executes it with the same loop, budgets and conversation store as every
other answer, and stores no agent. A run belongs to its member and to the installation that
started it.

## Run an agent configuration for a member

`POST /v1/workspaces/{workspaceId}/runs`

Runs `agent` on `input` for the acting member and answers at once with the run queued;
follow it with `GET …/runs/{runId}`, or send `Accept: text/event-stream` to receive the run as
server-sent events instead (`RunEvents`). A new conversation of that member holds it, or the
run conversation `conversationId` names: one this member started from this installation
(another is not found), with no run of it still in progress (`RUN_IN_PROGRESS`). Each run
may pass a different `agent`; each answers from its own.

`background: true` is an automation with no reader waiting: besides the workspace's limits it
may take no more than one automation's share of the workspace's rolling spending window,
measured on this installation's runs (`RUN_BUDGET_REFUSED`), and it is not streamed.
`replyTo.eventId` names an `sdk-event/v1` event delivered to this installation's application,
accepted and not yet answered: the completed answer is delivered to that event's reply
target, as `POST /v1/sdk/replies` would, and the run's `replyTo.delivery` says whether it
was. `metadata` is kept with the run and answered back; the platform never reads it.

Everything that can refuse the run is decided before the conversation exists, and a refusal
stores nothing: the whole configuration and input are checked and every problem is answered
at once (`RUN_CONFIGURATION_INVALID`, 422, with `problems`); a field this operation does not
name is refused, never ignored. `model` is `"auto"` (the workspace's default) or a model the
workspace may use (`GET …/models`), else `RUN_MODEL_UNAVAILABLE`; a workspace whose spending
limit refuses the run answers `RUN_BUDGET_REFUSED`.

Send `Idempotency-Key`: without one, a retried request is a second run, charged again.

Every MCP connection, document and Q&A entry the configuration names must be the
workspace's and one the member may use or read; one that is not refuses the whole run with
its field in `problems`, and the answer is the same whether the id is missing or another
workspace's or member's. A tool call that waits for a person puts the run in
`requires_action` with the calls in `requiredAction.toolApprovals`; decide each with
`POST …/runs/{runId}/tool-approvals/{toolCallId}`.

The configuration is stored with the run; identical configurations share one record within
the workspace. Sandbox, guardrails, a context provider and a tool credential join this
operation as new optional fields.

| Scope | 身分 | 驗證方式 | Idempotency-Key |
| --- | --- | --- | --- |
| `runs:write` | `member` | `installationToken` | 支援 |

### 參數

| 名稱 | 位置 | 型別 | 必填 | 說明 |
| --- | --- | --- | --- | --- |
| `workspaceId` | path | `string` | 是 | The workspace, by id. It must be the installation's. |
| `Agentlab-On-Behalf-Of` | header | `string` | 是 | The account id of the member the installation acts for: a current member of the workspace whose sign-in to the application there is still live, neither revoked nor expired. When the member's sign-in expires, the application acts for them again once they sign in again. |
| `Idempotency-Key` | header | `string` | 否 | Makes a creating call safe to retry. The same key and body within 24 hours answer the first answer again; the same key with a different body is 409. |

### 請求內容

`application/json`: [RunCreate](https://agentlab.cresclab.com/docs/zh-tw/api/schemas.md#RunCreate)

| 欄位 | 型別 | 必填 | 說明 |
| --- | --- | --- | --- |
| `conversationId` | `string (uuid)` | 否 | A run conversation of this member and installation to continue; omitted starts a new one. |
| `agent` | [AgentConfig](https://agentlab.cresclab.com/docs/zh-tw/api/schemas.md#AgentConfig) | 是 | — |
| `input` | [RunInputMessage](https://agentlab.cresclab.com/docs/zh-tw/api/schemas.md#RunInputMessage)[] | 是 | The member's message. |
| `background` | `boolean` | 否 | An automation with no reader waiting; not streamed. 預設值: `false`. |
| `replyTo` | `object` | 否 | — |
| `replyTo.eventId` | `string (uuid)` | 是 | The `eventId` of an `sdk-event/v1` event delivered to this installation's application, accepted and not yet answered, that no other run answers (a run that failed, was cancelled or could not deliver no longer does). |
| `metadata` | [RunMetadata](https://agentlab.cresclab.com/docs/zh-tw/api/schemas.md#RunMetadata) | 否 | — |

### 回應

| 狀態碼 | 內容 | 說明 |
| --- | --- | --- |
| `200` | `text/event-stream`: [RunEvents](https://agentlab.cresclab.com/docs/zh-tw/api/schemas.md#RunEvents) | The run's events, when `Accept: text/event-stream` asked for them. |
| `202` | `application/json`: [Run](https://agentlab.cresclab.com/docs/zh-tw/api/schemas.md#Run) | The run, queued. |
| `400` | `application/json`: [Error](https://agentlab.cresclab.com/docs/zh-tw/api/schemas.md#Error) | The request itself is wrong, such as a `cursor` this list did not answer (`recovery: none`). |
| `401` | `application/json`: [Error](https://agentlab.cresclab.com/docs/zh-tw/api/schemas.md#Error) | No token, or a token the platform does not honor. |
| `402` | `application/json`: [Error](https://agentlab.cresclab.com/docs/zh-tw/api/schemas.md#Error) | `RUN_BUDGET_REFUSED`: the workspace's spending limit refuses the run; nothing ran (`configure`). |
| `403` | `application/json`: [Error](https://agentlab.cresclab.com/docs/zh-tw/api/schemas.md#Error) | Refused as `MemberForbidden` says (including `PRODUCT_ACCESS_DENIED`), or `MEMBER_INACTIVE`: the member is no longer an active member, or between the checks and the start the member's seat or the installation stopped admitting the run; nothing ran (`authorize`). |
| `404` | `application/json`: [Error](https://agentlab.cresclab.com/docs/zh-tw/api/schemas.md#Error) | No such operation or resource. |
| `409` | `application/json`: [Error](https://agentlab.cresclab.com/docs/zh-tw/api/schemas.md#Error) | `RUN_IN_PROGRESS`: the conversation's previous run has not finished (`retry`); `CONVERSATION_LIMIT_REACHED`: the conversation holds as many messages as it may, start a new one (`none`); or the `Idempotency-Key` was used within 24 hours for a different request (`none`), or its first request is still running (`retry`). Nothing ran. |
| `413` | `application/json`: [Error](https://agentlab.cresclab.com/docs/zh-tw/api/schemas.md#Error) | The body is larger than the operation accepts (`PAYLOAD_TOO_LARGE`, `recovery: none`). |
| `422` | `application/json`: [Error](https://agentlab.cresclab.com/docs/zh-tw/api/schemas.md#Error) | Refused before anything ran or was stored: `RUN_CONFIGURATION_INVALID`, the configuration or input has problems, each in `problems` with its field (`none`); `RUN_MODEL_UNAVAILABLE`, the workspace may not run on the named model (`configure`). |
| `429` | `application/json`: [Error](https://agentlab.cresclab.com/docs/zh-tw/api/schemas.md#Error) | Rate limited (`recovery: retry`). |
| `503` | `application/json`: [Error](https://agentlab.cresclab.com/docs/zh-tw/api/schemas.md#Error) | Try again later (`recovery: retry`). |

## Approve or reject a tool call a run waits on

`POST /v1/workspaces/{workspaceId}/runs/{runId}/tool-approvals/{toolCallId}`

Decides one call of `requiredAction.toolApprovals`, as a person approving it in the
console does: the same risk tiers (a call that writes, or declares nothing, needs a role
that may approve it), the same audit and the same continuation. The run is answered as it
stands after the decision; a rejected call is answered to the model as declined. A run or
call of another member, installation or workspace is not found.

`Idempotency-Key` makes a retry answer the first decision again; without one, a second
decision of the same call is `TOOL_CALL_NOT_PENDING`.

| Scope | 身分 | 驗證方式 | Idempotency-Key |
| --- | --- | --- | --- |
| `runs:write` | `member` | `installationToken` | 支援 |

### 參數

| 名稱 | 位置 | 型別 | 必填 | 說明 |
| --- | --- | --- | --- | --- |
| `workspaceId` | path | `string` | 是 | The workspace, by id. It must be the installation's. |
| `Agentlab-On-Behalf-Of` | header | `string` | 是 | The account id of the member the installation acts for: a current member of the workspace whose sign-in to the application there is still live, neither revoked nor expired. When the member's sign-in expires, the application acts for them again once they sign in again. |
| `runId` | path | `string` | 是 | The run, by id. |
| `toolCallId` | path | `string` | 是 | The tool call, by id (`requiredAction.toolApprovals[].id`). |
| `Idempotency-Key` | header | `string` | 否 | Makes a creating call safe to retry. The same key and body within 24 hours answer the first answer again; the same key with a different body is 409. |

### 請求內容

`application/json`: [ToolApprovalDecision](https://agentlab.cresclab.com/docs/zh-tw/api/schemas.md#ToolApprovalDecision)

| 欄位 | 型別 | 必填 | 說明 |
| --- | --- | --- | --- |
| `decision` | `string` | 是 | 可用值: `approve`, `reject`. |

### 回應

| 狀態碼 | 內容 | 說明 |
| --- | --- | --- |
| `200` | `application/json`: [Run](https://agentlab.cresclab.com/docs/zh-tw/api/schemas.md#Run) | The run, after the decision. |
| `400` | `application/json`: [Error](https://agentlab.cresclab.com/docs/zh-tw/api/schemas.md#Error) | The request itself is wrong, such as a `cursor` this list did not answer (`recovery: none`). |
| `401` | `application/json`: [Error](https://agentlab.cresclab.com/docs/zh-tw/api/schemas.md#Error) | No token, or a token the platform does not honor. |
| `403` | `application/json`: [Error](https://agentlab.cresclab.com/docs/zh-tw/api/schemas.md#Error) | Refused as `RunForbidden` says, or `TOOL_APPROVAL_NOT_PERMITTED`: the member's role may not approve a call of this risk; it still waits for someone whose role may (`none`). |
| `404` | `application/json`: [Error](https://agentlab.cresclab.com/docs/zh-tw/api/schemas.md#Error) | No such operation or resource. |
| `409` | `application/json`: [Error](https://agentlab.cresclab.com/docs/zh-tw/api/schemas.md#Error) | `TOOL_CALL_NOT_PENDING`: the call was already decided or no longer waits (`none`); or the `Idempotency-Key` conflict `IdempotencyConflict` describes. |
| `413` | `application/json`: [Error](https://agentlab.cresclab.com/docs/zh-tw/api/schemas.md#Error) | The body is larger than the operation accepts (`PAYLOAD_TOO_LARGE`, `recovery: none`). |
| `429` | `application/json`: [Error](https://agentlab.cresclab.com/docs/zh-tw/api/schemas.md#Error) | Rate limited (`recovery: retry`). |
| `503` | `application/json`: [Error](https://agentlab.cresclab.com/docs/zh-tw/api/schemas.md#Error) | Try again later (`recovery: retry`). |

## A run and its answer

`GET /v1/workspaces/{workspaceId}/runs/{runId}`

The run's status and, once completed, its answer; with `Accept: text/event-stream`, its
events from now on (`RunEvents`). A run of another member, another installation or another
workspace is not found.

| Scope | 身分 | 驗證方式 | Idempotency-Key |
| --- | --- | --- | --- |
| `runs:write` | `member` | `installationToken` | — |

### 參數

| 名稱 | 位置 | 型別 | 必填 | 說明 |
| --- | --- | --- | --- | --- |
| `workspaceId` | path | `string` | 是 | The workspace, by id. It must be the installation's. |
| `Agentlab-On-Behalf-Of` | header | `string` | 是 | The account id of the member the installation acts for: a current member of the workspace whose sign-in to the application there is still live, neither revoked nor expired. When the member's sign-in expires, the application acts for them again once they sign in again. |
| `runId` | path | `string` | 是 | The run, by id. |

### 回應

| 狀態碼 | 內容 | 說明 |
| --- | --- | --- |
| `200` | `application/json`: [Run](https://agentlab.cresclab.com/docs/zh-tw/api/schemas.md#Run); `text/event-stream`: [RunEvents](https://agentlab.cresclab.com/docs/zh-tw/api/schemas.md#RunEvents) | The run, or its events. |
| `400` | `application/json`: [Error](https://agentlab.cresclab.com/docs/zh-tw/api/schemas.md#Error) | The request itself is wrong, such as a `cursor` this list did not answer (`recovery: none`). |
| `401` | `application/json`: [Error](https://agentlab.cresclab.com/docs/zh-tw/api/schemas.md#Error) | No token, or a token the platform does not honor. |
| `403` | `application/json`: [Error](https://agentlab.cresclab.com/docs/zh-tw/api/schemas.md#Error) | Refused as `MemberForbidden` says (including `PRODUCT_ACCESS_DENIED`), or `MEMBER_INACTIVE`: the member is no longer an active member, or between the checks and the start the member's seat or the installation stopped admitting the run; nothing ran (`authorize`). |
| `404` | `application/json`: [Error](https://agentlab.cresclab.com/docs/zh-tw/api/schemas.md#Error) | No such operation or resource. |
| `429` | `application/json`: [Error](https://agentlab.cresclab.com/docs/zh-tw/api/schemas.md#Error) | Rate limited (`recovery: retry`). |
| `503` | `application/json`: [Error](https://agentlab.cresclab.com/docs/zh-tw/api/schemas.md#Error) | Try again later (`recovery: retry`). |

## Cancel a run

`POST /v1/workspaces/{workspaceId}/runs/{runId}/cancel`

Stops the run as the console's stop does: what the answer had written is kept, tool calls
that had not run are not run, and the platform stops spending on it. Answers the run, now
`failed` with `cancelled: true`, or as it settled if it settled first; cancelling again
changes nothing. Only the
member and installation that started the run may cancel it; another run is not found.

| Scope | 身分 | 驗證方式 | Idempotency-Key |
| --- | --- | --- | --- |
| `runs:write` | `member` | `installationToken` | — |

### 參數

| 名稱 | 位置 | 型別 | 必填 | 說明 |
| --- | --- | --- | --- | --- |
| `workspaceId` | path | `string` | 是 | The workspace, by id. It must be the installation's. |
| `Agentlab-On-Behalf-Of` | header | `string` | 是 | The account id of the member the installation acts for: a current member of the workspace whose sign-in to the application there is still live, neither revoked nor expired. When the member's sign-in expires, the application acts for them again once they sign in again. |
| `runId` | path | `string` | 是 | The run, by id. |

### 回應

| 狀態碼 | 內容 | 說明 |
| --- | --- | --- |
| `200` | `application/json`: [Run](https://agentlab.cresclab.com/docs/zh-tw/api/schemas.md#Run) | The run after the stop. |
| `400` | `application/json`: [Error](https://agentlab.cresclab.com/docs/zh-tw/api/schemas.md#Error) | The request itself is wrong, such as a `cursor` this list did not answer (`recovery: none`). |
| `401` | `application/json`: [Error](https://agentlab.cresclab.com/docs/zh-tw/api/schemas.md#Error) | No token, or a token the platform does not honor. |
| `403` | `application/json`: [Error](https://agentlab.cresclab.com/docs/zh-tw/api/schemas.md#Error) | Refused as `MemberForbidden` says (including `PRODUCT_ACCESS_DENIED`), or `MEMBER_INACTIVE`: the member is no longer an active member, or between the checks and the start the member's seat or the installation stopped admitting the run; nothing ran (`authorize`). |
| `404` | `application/json`: [Error](https://agentlab.cresclab.com/docs/zh-tw/api/schemas.md#Error) | No such operation or resource. |
| `429` | `application/json`: [Error](https://agentlab.cresclab.com/docs/zh-tw/api/schemas.md#Error) | Rate limited (`recovery: retry`). |
| `503` | `application/json`: [Error](https://agentlab.cresclab.com/docs/zh-tw/api/schemas.md#Error) | Try again later (`recovery: retry`). |
