# sessions.agent_attach

`POST /api/public/v1/sessions/{id}/agent-attach`

Reserve reader or writer agent lease; writers additionally require agent.act in the database. This is not a CDP connection ticket.

- Capability: `agent.observe`
- Command (idempotent): No
- MCP tool: `sessions_agent_attach`

## Parameters

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `id` | path | string (uuid) | Yes |  |
| `idempotency_key` | body | string | Yes | (min length 1, max length 163) |
| `holder_kind` | body | "api" \| "mcp" \| "rpa" \| "cdp" \| "human" | Yes |  |
| `mode` | body | "reader" \| "writer" | No | Default: `"writer"`. |
| `epoch` | body | integer | No | (min 0, max 9007199254740991) |
| `ttl_seconds` | body | integer | No | (min 1, max 900) Default: `300`. |
| `control_mode` | body | "quiet" \| "compat" | No | Default: `"quiet"`. |

## Response

`200` with `{ data, correlation_id }`.

The field list of this reply is not published yet; read data as JSON.

## Errors

| Code | HTTP | Retryable |
|---|---|---|
| `UNAUTHENTICATED` | 401 | No |
| `FORBIDDEN` | 403 | No |
| `RATE_LIMITED` | 429 | Yes |
| `VALIDATION_FAILED` | 422 | No |
| `NOT_FOUND` | 404 | No |
| `DEPENDENCY_UNAVAILABLE` | 503 | Yes |
| `UNKNOWN` | 500 | No |

## Examples (curl)

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

## Examples (TypeScript SDK)

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

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

## Examples (Python)

```python
import os
import requests

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

## Examples (MCP)

```json
{
  "method": "tools/call",
  "params": {
    "name": "sessions_agent_attach",
    "arguments": {
      "id": "<id>",
      "idempotency_key": "<idempotency_key>",
      "holder_kind": "api"
    }
  }
}
```
