> ## Documentation Index
> Fetch the complete documentation index at: https://developers.telnyx.com/llms.txt
> Use this file to discover all available pages before exploring further.

# API Conventions

> Base URL, authentication, access checks, response envelope, pagination, idempotency, long polls, and streaming connections for the GPU Sandboxes API.

## Base URL and Authentication

All endpoints are under `https://api.telnyx.com/v2/ai`. Authenticate with a Telnyx API key as a Bearer token. The Telnyx CLI (`telnyx-edge sandbox-gpu`) calls the same API with the same key, which it stores with `telnyx-edge auth api-key set`.

```bash CLI theme={null}
telnyx-edge auth api-key set "$TELNYX_API_KEY"
telnyx-edge sandbox-gpu list
```

```bash curl theme={null}
curl -H "Authorization: Bearer $TELNYX_API_KEY" https://api.telnyx.com/v2/ai/sandboxes
```

Sandboxes, execs, and idempotency keys belong to the organization of the API key. Every user in the organization sees and manages its sandboxes; GPU limits and billing are per organization.

IDs are prefixed: `sb-…` for sandboxes and `exec-…` for execs.

## Access

GPU Sandboxes is available only to [fully verified accounts](https://developers.telnyx.com/docs/account-setup/levels-and-capabilities/verified.md) enabled for the invite-only preview. Every endpoint refuses an account that isn't fully verified, and every endpoint except the access check refuses one that isn't enabled:

| Status | Error | Meaning |
| - | - | - |
| `403` | `sandboxes_require_verification` | The account isn't fully verified. |
| `403` | `sandboxes_not_whitelisted` | The account isn't enabled for the preview. |

### Check Access

```bash theme={null}
curl -H "Authorization: Bearer $TELNYX_API_KEY" https://api.telnyx.com/v2/ai/sandbox-access
```

```json theme={null}
{ "data": { "whitelisted": true } }
```

`whitelisted: true` means the other endpoints are available as far as the preview goes. Account verification, GPU limits, and the errors below still apply:

| Status | Error | Meaning |
| - | - | - |
| `403` | `sandboxes_disabled` | Creating sandboxes and starting execs is disabled for the account. Other operations keep working. |
| `403` | `sandboxes_spend_limit_reached` | The account, or the API key the call was made with, has reached its GPU Sandboxes spend limit. Returned when creating a sandbox. |
| `503` | `sandbox_creation_paused` | Creating sandboxes is paused for everyone. Retry later. |

## Responses

A single object is returned as `{"data": {...}}`. A list is returned as `{"data": [...], "meta": {...}}`.

Lists page by number with `page[number]` (1-based, default 1) and `page[size]` (default 20, maximum 100):

```json theme={null}
{ "meta": { "page_number": 1, "page_size": 20, "total_pages": 3, "total_results": 47 } }
```

[Logs](https://developers.telnyx.com/docs/gpu-sandboxes/logs.md#read-pages) are the one exception: they page by cursor with `page[after]`.

## Idempotency

Every side-effecting endpoint accepts an `Idempotency-Key` header: any client-chosen string of up to 255 characters, such as a UUID.

* **Same key, same request**, within 24 hours: the stored response is returned, with the same resource ID and status code, and nothing happens twice.
* **Same key, different request**: `422 idempotency_key_reused`.
* **Same key while the first request is still running**: `409 request_in_progress`. Retry later.
* **Failed requests aren't stored.** A retry with the same key after a validation error, `429`, or conflict is evaluated afresh.

The CLI sends a new key with every write and reuses it when it retries. To make a retry across runs safe too, pass your own key: `--idempotency-key` on the CLI's `create`, `exec`, `terminate`, `set-tags`, and `files put`.

> [!WARNING]
>
> Always send an `Idempotency-Key` with `POST /v2/ai/sandboxes` and `POST …/execs`. Without one, a retry after a lost response can start, and bill, a second GPU sandbox, or run a command twice. The CLI sends one for you.

| Endpoint | Key |
| - | - |
| `POST /v2/ai/sandboxes` | Recommended |
| `POST /v2/ai/sandboxes/{sandbox_id}/execs` | Recommended |
| `PATCH /v2/ai/sandboxes/{sandbox_id}`, `POST …/terminate`, `POST …/stdin/close`, `POST …/execs/{exec_id}/kill`, `POST …/execs/{exec_id}/stdin/close`, `PUT` and `DELETE …/files` | Accepted |

## Long Polls

`GET …/wait` and `GET …/execs/{exec_id}?wait=` hold the request for at most 10 seconds and then return `200` with the current state. Larger values are clamped. Loop until the state is final. The CLI's `wait` loops for you:

```bash CLI theme={null}
telnyx-edge sandbox-gpu wait "$SANDBOX_ID"
```

```bash curl theme={null}
until [[ $(curl -sS -H "Authorization: Bearer $TELNYX_API_KEY" \
  "https://api.telnyx.com/v2/ai/sandboxes/$SANDBOX_ID/wait?timeout=10" | jq -r '.data.state') == terminated ]]; do :; done
```

## Streaming Connections

The [attach WebSockets](https://developers.telnyx.com/docs/gpu-sandboxes/attach.md) and the [log stream](https://developers.telnyx.com/docs/gpu-sandboxes/logs.md#follow-live) are cut by the edge proxy after about 600 seconds. Both resume without gaps or duplicates: exec attach from a byte `offset`, logs from the last event `id`. Plan to reconnect. The CLI reconnects for you.

## Errors

Errors use the standard Telnyx error body. See [Errors](https://developers.telnyx.com/docs/gpu-sandboxes/errors.md).
