# sessions.attach

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

Short-lived attach ticket for the session's loopback CDP broker (client must run on that machine).

- Capability: `session.attach`
- Command: no
- MCP tool: `sessions_attach`

## Parameters

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `id` | path | string (uuid) | yes | Session id |
| `ttl_seconds` | body | integer | no | (min 30, max 900) Default: `300`. |

## Response

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

| Field | Type | Always present | Description |
|---|---|---|---|
| `data` | object | yes |  |
| `data.ticket` | string | yes | Send as Authorization: Bearer <ticket> to the endpoint |
| `data.ticket_id` | string (uuid) | yes |  |
| `data.session_id` | string (uuid) | yes |  |
| `data.device_id` | string (uuid) | yes |  |
| `data.fence` | integer | yes | (min -9007199254740991, max 9007199254740991) |
| `data.scope` | "cdp.full" \| "cdp.observe" \| "view.page" \| "control.page" \| "sync.target" | yes |  |
| `data.endpoint` | string | yes | Loopback CDP broker on the machine running the browser |
| `data.header` | string | yes |  |
| `data.expires_at` | string (date-time) | yes |  |
| `correlation_id` | string (uuid) | yes |  |

New fields can appear at any time; ignore the ones you do not know.

## 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 |

## Example (curl)

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

## Example (TypeScript SDK)

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

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

## Example (Python)

```python
import os
import requests

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

## Example (MCP)

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