<span id="获取任务浏览器短期令牌"></span>

# Get a short-lived task browser token

```{raw} html
<div class="mo-api-page-show-toc" aria-hidden="true"></div>
```

Obtain short-lived identity proof for the browser connection of an existing task you own. This does not create a replacement environment or start a new browser.

```text
POST https://api.moi.matrixorigin.cn/v5/workspaces/{workspace_id}/agent-runtime-tasks/{task_id}/browser/token
```

<span id="调用前准备"></span>

## Before you call this API

Prepare current product identity and workspace ID. The task must belong to the current user, have conversation context, be admitted for sandbox tools, and have its original browser available. Current agent-use permission must remain valid.

<span id="请求参数"></span>

## Request parameters

:::::::{div} mo-api-tabs
::::::{tab-set}
:::::{tab-item} Request example

```bash
curl -X POST "https://api.moi.matrixorigin.cn/v5/workspaces/$WORKSPACE_ID/agent-runtime-tasks/$TASK_ID/browser/token" \
  -H "X-API-Key: $AI_STUDIO_API_KEY" \
  -H "X-Workspace-ID: $WORKSPACE_ID" \
  -H "Content-Type: application/json" --data '{}'
```

:::::
:::::{tab-item} Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| `workspace_id` | string | Workspace owning your task. |
| `task_id` | string | Original run task ID. |
| Product identity header | string | The example uses a personal access token from the current environment. |
| Body | object | No business fields; the example sends {}. |

:::::
::::::
:::::::

<span id="成功响应"></span>

## Successful response

:::::::{div} mo-api-tabs mo-api-response-tabs
::::::{tab-set}
:::::{tab-item} Response example

```json
{
  "code": 0,
  "data": {
    "token": "moi-browser-token-v1.example",
    "expires_at": "2026-11-12T04:01:00Z"
  }
}
```

:::::
:::::{tab-item} Fields

| Field or response item | Type | Description |
| --- | --- | --- |
| `code` | integer | 0 on success. |
| `data.token` | string | Short-lived opaque proof, passed as a WebSocket subprotocol rather than in the URL. |
| `data.expires_at` | string | RFC3339 expiration time. Current proof validity is 60 seconds; connections still reauthorize. |
| `Cache-Control` | HTTP header | Successful responses use no-store. |

:::::
::::::
:::::::

<span id="错误响应"></span>

## Error responses

| HTTP / code | Condition |
| --- | --- |
| 400 / 2 | Invalid browser parameters. |
| 401 / 6 | Invalid identity proof, or stream proof does not match the path. |
| 403 / 5 | Current authorization denied, or stream Origin/subprotocol requirements unmet. |
| 404 / 3 | Task inaccessible, owned by another user, or missing required context. |
| 409 / 15 | Existing browser is not running; details.reason=BROWSER_NOT_RUNNING. |
| 410 / 3 | Original environment ended or expired; details.reason=BROWSER_SESSION_ENDED. |
| 503 / 15 | Browser runtime dependencies unavailable, or task state unusable. |
| 500 / 1 | Other internal failure. |

After 101 upgrade, ordinary HTTP JSON errors no longer apply. Periodic recheck failures may close the connection. See [environments and errors](errors-environments.md) for recovery.

Product authentication may also use string code/msg. The numeric errors above do not enumerate every authentication envelope.
