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

# Logs

> Read a sandbox's stdout and stderr page by page, or follow them live as Server-Sent Events. Logs are stored in your own Telnyx Cloud Storage bucket.

`GET /v2/ai/sandboxes/{sandbox_id}/logs` returns the output (stdout and stderr) of the sandbox's main process. Exec output isn't included; read it through the [exec attach](https://developers.telnyx.com/docs/gpu-sandboxes/attach.md#exec-attach).

| `follow` | Response |
| - | - |
| `false` (default) | One page of stored output as JSON (`application/json`). |
| `true` | A Server-Sent Events stream (`text/event-stream`): stored output, then new output as it is stored, until the sandbox ends. |

`stream=stdout` or `stream=stderr` keeps only that stream's lines, and the gaps that touch it, with either value of `follow`.

## Entries

Each entry is a `line` or a `gap`, and carries a `position`:

```json theme={null}
{ "type": "line", "stream": "stdout", "ts": "2026-11-13T10:15:02.123456789Z", "line": "epoch 1/3 loss=0.412", "position": "p1.18.0" }
```

| Field | Description |
| - | - |
| `stream` | `stdout` or `stderr`. |
| `ts` | When the line was written, to the nanosecond. |
| `line` | The text without its newline. Lines are cut at 256 KiB, and bytes that weren't valid UTF-8 appear as U+FFFD. |
| `position` | Opaque position. Pass it as `page[after]` or `Last-Event-ID` to continue right after this entry. |

Lines are in the order they were stored, which closely follows the order the sandbox printed them; lines a few seconds apart can interleave. Output reaches the API a few seconds after the sandbox prints it.

Output that isn't available appears in place as a `gap`, never silently skipped:

```json theme={null}
{ "type": "gap", "reason": "expired", "stream": null, "from_ts": "2026-10-01T08:00:00Z", "to_ts": "2026-10-01T09:12:44Z", "records": null, "position": "p1.4.0" }
```

| `reason` | Meaning |
| - | - |
| `expired` | Past its retention, or removed or changed in the bucket. |
| `log_bucket_unavailable` | The log bucket couldn't be written, so the output wasn't stored. |
| `size_cap_reached` | The sandbox's output passed the size cap. |

`stream`, `from_ts`, `to_ts`, and `records` are `null` when unknown; a `null` `stream` means the gap touches both streams.

Only pass positions the API returned. Any other value is `422`.

## Read Pages

Paging uses a cursor, because the log keeps growing. `page[size]` is 1–100 (default 20). Pass `meta.next_page_after` as `page[after]` for the next page; omit `page[after]` to start at the beginning of the retained log.

```bash CLI theme={null}
telnyx-edge sandbox-gpu logs "$SANDBOX_ID"
telnyx-edge sandbox-gpu logs "$SANDBOX_ID" --json --after "$AFTER"
```

```bash curl theme={null}
curl -sS -G "https://api.telnyx.com/v2/ai/sandboxes/$SANDBOX_ID/logs" \
  -H "Authorization: Bearer $TELNYX_API_KEY" \
  --data-urlencode "page[size]=100" \
  --data-urlencode "page[after]=$AFTER"
```

```json theme={null}
{
  "data": [ { "type": "line", "stream": "stdout", "ts": "…", "line": "…", "position": "p1.18.0" } ],
  "meta": { "page_size": 100, "next_page_after": null }
}
```

`meta.next_page_after` is `null` once the end of what is stored so far is reached. To poll a running sandbox, keep the last entry's `position` and read again later.

The CLI reads every page for you: the sandbox's stdout lines go to your stdout and its stderr lines to your stderr, with gaps shown in place. `--json` prints one entry per line, with its `position`, and `--after` starts after a position.

## Follow Live

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

```bash curl theme={null}
curl -sS -N "https://api.telnyx.com/v2/ai/sandboxes/$SANDBOX_ID/logs?follow=true" \
  -H "Authorization: Bearer $TELNYX_API_KEY" \
  -H "Accept: text/event-stream"
```

With `-f`, the CLI resumes a dropped stream where it left off and returns once the sandbox has ended and every line was printed, saying whether the log is complete. The stream itself:

```text theme={null}
event: log
id: p1.18.0
data: {"type":"line","stream":"stdout","ts":"2026-11-13T10:15:02.123456789Z","line":"epoch 1/3 loss=0.412","position":"p1.18.0"}

: heartbeat

event: end
data: {"logs":"complete","reason":null}
```

| Event | Data |
| - | - |
| `log` | A `line` entry. Its `id` is the line's position. |
| `gap` | A `gap` entry. Its `id` is the gap's position. |
| `end` | How the log ended. Sent once the sandbox has ended and every stored line was sent; the stream then closes. |

A comment line (`: heartbeat`) arrives every 30 seconds. A sandbox that hasn't ended, queued sandboxes included, never gets `end`.

Connections can be cut, for example by the edge proxy after about 600 seconds. Reconnect with the `Last-Event-ID` header (or `page[after]`) set to the last `id` received to continue without gaps or duplicates. When both are given, `page[after]` wins.

### End of Log

`end` carries the log's final status:

| `logs` | Meaning |
| - | - |
| `complete` | Every line the sandbox printed is stored. |
| `incomplete` | Some output is missing for good. `reason` says why. |
| `settling` | The sandbox ended a while ago and its log isn't final yet. A later read may return more. |

The sandbox itself shows the same outcome in `logs_incomplete` and `logs_incomplete_reason`:

| Reason | Meaning |
| - | - |
| `log_bucket_unavailable` | The log bucket couldn't be written. |
| `node_lost` | The sandbox's node was lost. |
| `logs_missing` | Output was lost on its way to storage. |
| `logs_unverified` | The sandbox's output couldn't be counted, so the log can't be shown complete. |
| `size_cap_reached` | The output passed the size cap. |

## Log Bucket

Logs are stored in a [Telnyx Cloud Storage](https://developers.telnyx.com/docs/cloud-storage/overview.md) bucket in your account. The sandbox's `log_bucket` field names it, and is `null` until the bucket is known.

* **Default.** Without `log_bucket`, the sandbox uses a bucket created for you in your account, with a 30-day lifecycle rule. An account's first sandbox can wait for that bucket to be created before it waits for capacity.
* **Your own bucket.** `log_bucket` on create names a bucket of yours. It must exist, belong to your organization, be in the Cloud Storage region GPU Sandboxes stores logs in, and be writable; otherwise the create fails with `422 log_bucket_not_allowed`. Retention is whatever lifecycle rules the bucket has.

### Object Layout

The logs can be read with any S3-compatible tool under `sandboxes/{sandbox_id}/` in the bucket. Objects are zstd-compressed NDJSON, one record per line:

```json theme={null}
{"ts": "2026-11-13T10:15:02.123456789Z", "stream": "stdout", "line": "epoch 1/3 loss=0.412"}
```

| Object | When |
| - | - |
| `sandboxes/{sandbox_id}/chunks/<sha256>.ndjson.zst` | Chunks, written while the sandbox runs. |
| `sandboxes/{sandbox_id}/logs-<id>-<nnnn>.ndjson.zst` | The whole log, once it is final. |

Removing or changing these objects shows up as `expired` gaps in the API.

## Limits

* Each organization can have a limited number of log streams open at once. Beyond it, a request fails with `429 too_many_log_readers`; close a stream or retry later.
* Output is subject to a per-sandbox size cap. Output beyond it is reported as a `size_cap_reached` gap.
