# pages.state

`POST /api/public/v1/sessions/{id}/page-state`

Yêu cầu thay đổi cây truy cập của tab chỉ định; không tự chụp ảnh.

- Quyền: `agent.observe`
- Lệnh (chống trùng): Không
- Chống trùng: gửi cùng `idempotency_key` khi thử lại; không tạo khóa mới.
- Tool MCP: `pages_state`

## Tham số

| Tên | Vị trí | Kiểu | Bắt buộc | Mô tả |
|---|---|---|---|---|
| `id` | path | string (uuid) | Có |  |
| `idempotency_key` | body | string | Có | (độ dài tối thiểu 1, độ dài tối đa 163) |
| `target_id` | body | string | Có | (độ dài tối thiểu 1, độ dài tối đa 128) |
| `token_budget` | body | integer | Không | (tối thiểu 256, tối đa 3000000) Mặc định: `16000`. |
| `interactive_only` | body | boolean | Không | Mặc định: `false`. |

## Phản hồi

200 với { data, correlation_id }.

| Trường | Kiểu | Luôn có | Mô tả |
|---|---|---|---|
| `operation_id` | string (uuid) \| null | Có |  |
| `state_version` | integer | Có | (tối thiểu 0, tối đa 9007199254740991) |
| `retryable` | false | Có |  |
| `next` | object \| null | Có |  |
| `next.operation` | "operations.get" | Có |  |
| `next.operation_id` | string (uuid) | Có |  |
| `ok` | true | Có |  |
| `data` | object | Có |  |

Trường mới có thể xuất hiện bất cứ lúc nào; hãy bỏ qua trường bạn không biết.

## Lỗi

| Mã | HTTP | Thử lại |
|---|---|---|
| `UNAUTHENTICATED` | 401 | Không |
| `FORBIDDEN` | 403 | Không |
| `RATE_LIMITED` | 429 | Có |
| `VALIDATION_FAILED` | 422 | Không |
| `NOT_FOUND` | 404 | Không |
| `ACTION_OUTCOME_UNKNOWN` | 202 | Không |
| `IDEMPOTENCY_KEY_REUSED` | 409 | Không |
| `DEPENDENCY_UNAVAILABLE` | 503 | Có |
| `UNKNOWN` | 500 | Không |

## Ví dụ (curl)

```bash
curl -X POST "https://browlix.com/api/public/v1/sessions/<id>/page-state" \
  -H "Authorization: Bearer $BROWLIX_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"idempotency_key":"<idempotency_key>","target_id":"<target_id>"}'
```

## Ví dụ (TypeScript SDK)

```ts
import { Browlix } from "@browlix/sdk";

const bx = new Browlix({ apiKey: process.env.BROWLIX_API_KEY! });
const reply = await bx.call("pages.state", { path: { id: "<id>" }, body: {"idempotency_key":"<idempotency_key>","target_id":"<target_id>"} });
console.log(reply.data);
```

## Ví dụ (Python)

```python
import os
import requests

r = requests.post(
    "https://browlix.com/api/public/v1/sessions/<id>/page-state",
    headers={"Authorization": f"Bearer {os.environ['BROWLIX_API_KEY']}"},
    json={"idempotency_key":"<idempotency_key>","target_id":"<target_id>"},
    timeout=60,
)
print(r.status_code, r.json())
```

## Ví dụ (MCP)

```json
{
  "method": "tools/call",
  "params": {
    "name": "pages_state",
    "arguments": {
      "id": "<id>",
      "idempotency_key": "<idempotency_key>",
      "target_id": "<target_id>"
    }
  }
}
```
