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

# Read or follow a sandbox's logs

> The output (stdout and stderr) of the sandbox's main process. Exec output isn't included; read it through the exec attach WebSocket.

- **`follow=false` (default):** one page of stored output as JSON, in order. Paging uses a cursor, not page numbers, because the log keeps growing: pass `meta.next_page_after` as `page[after]` for the next page. `meta.next_page_after` is `null` once you've reached the end of what's stored so far; keep your last position to poll a running sandbox.
- **`follow=true`:** a Server-Sent Events stream (`text/event-stream`): the output stored so far, then new output a few seconds after the sandbox prints it. Every `log` and `gap` event's `id` is a position: after a cut connection (e.g. the edge proxy's ~600 s connection limit), reconnect with `Last-Event-ID` (or `page[after]`) to continue without gaps or duplicates. A heartbeat comment arrives every 30 s. Once the sandbox has ended and every stored line was sent, an `end` event says how its log ended: `complete`, `incomplete` (with `reason`), or `settling` (a later read may return more); then the stream closes. A sandbox that hasn't ended, queued ones included, never gets `end`.

Every line names its stream, and `stream=stdout|stderr` keeps only that stream's lines (and the gaps that touch it), with either value of `follow`. Lines are in the order they were stored, which closely follows the order the sandbox printed them (lines a few seconds apart can interleave); each carries the time it was written, to the nanosecond. Lines are cut at 256 KiB, and bytes that weren't valid UTF-8 appear as U+FFFD.

Output that isn't available is shown in place as a `gap` entry, never skipped, with its reason: `expired` (past its retention, or removed or changed in your bucket), `log_bucket_unavailable` (your bucket couldn't be written) or `size_cap_reached`. A position that isn't one this API returned is a `422`.

The logs are stored in your own Cloud Storage bucket (the sandbox's `log_bucket`), where you can also read them with any S3 tool: under `sandboxes/{sandbox_id}/`, zstd-compressed NDJSON objects, one record per line, `{"ts": …, "stream": "stdout"|"stderr", "line": …}`: chunk objects (`chunks/<sha256>.ndjson.zst`) while the sandbox runs, then the whole log as `logs-<id>-<nnnn>.ndjson.zst`.



## OpenAPI

````yaml /openapi/source/external/sandboxes/sandboxes.json get /ai/sandboxes/{sandbox_id}/logs
openapi: 3.1.0
info:
  title: Telnyx API
  version: 1.0.0
  description: >-
    Run a container image of your choice on a whole GPU node, each sandbox in
    its own virtual machine, for seconds or indefinitely. Run commands inside
    it, move files in and out, stream its logs, read its metrics, and pay per
    second while it runs.


    ## Preview


    GPU Sandboxes is in an invite-only preview. `GET /ai/sandbox-access` tells
    whether it is enabled for your organization.


    ## Authentication


    All endpoints require a Telnyx API key sent as a Bearer token in the
    `Authorization` header.


    ## Retries


    Every side-effecting endpoint accepts an `Idempotency-Key` header. Send one
    on `POST /ai/sandboxes` and `POST /ai/sandboxes/{sandbox_id}/execs`, so a
    retry after a lost response doesn't start (and bill) a second workload.


    ## Errors


    Errors use the standard Telnyx error body. General errors carry their
    5-digit `code` (e.g. `10009`); Sandboxes-specific errors are identified by
    their name in `title` (e.g. `quota_exceeded`).
  contact:
    email: support@telnyx.com
  x-latency-category: responsive
  x-endpoint-cost: light
servers:
  - url: https://api.telnyx.com/v2
    description: Telnyx API v2
security:
  - bearerAuth: []
tags:
  - name: Sandboxes
    description: >-
      Create, find, wait for, tag and terminate sandboxes, and close the main
      process's stdin.
  - name: Sandbox execs
    description: Run commands in a running sandbox.
  - name: Sandbox files
    description: Read, write, list and delete files inside a running sandbox.
  - name: Sandbox logs
    description: The main process's stored and live output.
  - name: Sandbox metrics
    description: CPU, network, memory, disk and GPU usage.
  - name: Sandbox GPU types
    description: What you can rent, and at what price.
  - name: Sandbox access
    description: Whether Sandboxes is enabled for your organization.
paths:
  /ai/sandboxes/{sandbox_id}/logs:
    get:
      tags:
        - Sandbox logs
      summary: Read or follow a sandbox's logs
      description: >-
        The output (stdout and stderr) of the sandbox's main process. Exec
        output isn't included; read it through the exec attach WebSocket.


        - **`follow=false` (default):** one page of stored output as JSON, in
        order. Paging uses a cursor, not page numbers, because the log keeps
        growing: pass `meta.next_page_after` as `page[after]` for the next page.
        `meta.next_page_after` is `null` once you've reached the end of what's
        stored so far; keep your last position to poll a running sandbox.

        - **`follow=true`:** a Server-Sent Events stream (`text/event-stream`):
        the output stored so far, then new output a few seconds after the
        sandbox prints it. Every `log` and `gap` event's `id` is a position:
        after a cut connection (e.g. the edge proxy's ~600 s connection limit),
        reconnect with `Last-Event-ID` (or `page[after]`) to continue without
        gaps or duplicates. A heartbeat comment arrives every 30 s. Once the
        sandbox has ended and every stored line was sent, an `end` event says
        how its log ended: `complete`, `incomplete` (with `reason`), or
        `settling` (a later read may return more); then the stream closes. A
        sandbox that hasn't ended, queued ones included, never gets `end`.


        Every line names its stream, and `stream=stdout|stderr` keeps only that
        stream's lines (and the gaps that touch it), with either value of
        `follow`. Lines are in the order they were stored, which closely follows
        the order the sandbox printed them (lines a few seconds apart can
        interleave); each carries the time it was written, to the nanosecond.
        Lines are cut at 256 KiB, and bytes that weren't valid UTF-8 appear as
        U+FFFD.


        Output that isn't available is shown in place as a `gap` entry, never
        skipped, with its reason: `expired` (past its retention, or removed or
        changed in your bucket), `log_bucket_unavailable` (your bucket couldn't
        be written) or `size_cap_reached`. A position that isn't one this API
        returned is a `422`.


        The logs are stored in your own Cloud Storage bucket (the sandbox's
        `log_bucket`), where you can also read them with any S3 tool: under
        `sandboxes/{sandbox_id}/`, zstd-compressed NDJSON objects, one record
        per line, `{"ts": …, "stream": "stdout"|"stderr", "line": …}`: chunk
        objects (`chunks/<sha256>.ndjson.zst`) while the sandbox runs, then the
        whole log as `logs-<id>-<nnnn>.ndjson.zst`.
      operationId: GetSandboxLogs
      parameters:
        - description: Sandbox ID (`sb-…`).
          in: path
          name: sandbox_id
          required: true
          schema:
            maxLength: 64
            minLength: 1
            type: string
          example: sb-0192f1c2-7a4b-7c3e-9d1e-2f3a4b5c6d7e
        - description: >-
            `false`: one page of stored output as JSON. `true`: a Server-Sent
            Events stream of the stored output, then new output as it's stored,
            until the sandbox ends.
          in: query
          name: follow
          required: false
          schema:
            default: false
            type: boolean
        - description: >-
            Only `stdout` or only `stderr` (and the gaps that touch it), with
            either value of `follow`.
          in: query
          name: stream
          required: false
          schema:
            $ref: '#/components/schemas/LogStream'
        - description: >-
            Continue after this position (`meta.next_page_after`, or an event
            `id`). Omit it to start at the beginning of the retained log.
          in: query
          name: page[after]
          required: false
          schema:
            type: string
        - description: Entries per page (max 100); `follow=false` only.
          in: query
          name: page[size]
          required: false
          schema:
            default: 20
            maximum: 100
            minimum: 1
            type: integer
        - description: >-
            SSE resume: the last event `id` received. Same as `page[after]`,
            which wins when both are given.
          in: header
          name: Last-Event-ID
          required: false
          schema:
            type: string
      responses:
        '200':
          description: >-
            `follow=false`: a JSON page (`application/json`). `follow=true`: a
            Server-Sent Events stream (`text/event-stream`) of `log`, `gap` and
            `end` events, whose `data` are the JSON objects `LogLine`, `LogGap`
            and `LogEnd`.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/LogPageRespData'
              example:
                data:
                  - type: line
                    position: p1.12.0
                    ts: '2026-11-13T10:01:15.123456789Z'
                    stream: stdout
                    line: 'epoch 1/3: loss=2.314'
                  - type: gap
                    position: p1.12.1
                    reason: size_cap_reached
                    stream: null
                    records: null
                    from_ts: '2026-11-13T10:01:16Z'
                    to_ts: null
                meta:
                  next_page_after: p1.12.1
                  page_size: 20
            text/event-stream:
              schema:
                type: string
              example: >+
                id: p1.12.0

                event: log

                data:
                {"type":"line","position":"p1.12.0","ts":"2026-11-13T10:01:15.123456789Z","stream":"stdout","line":"epoch
                1/3: loss=2.314"}


                : heartbeat


                event: end

                data: {"logs":"complete","reason":null}

        '400':
          description: >-
            Validation error: the standard Telnyx validation errors (codes such
            as 10004 missing parameter, 10015 bad request, 10025 invalid string
            length, 10026 invalid type).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TelnyxErrors'
        '401':
          description: Missing or invalid API key (code 10009).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TelnyxErrors'
              example:
                errors:
                  - code: '10009'
                    title: Authentication failed
                    detail: Could not find any usable credentials in the request.
        '403':
          description: >-
            - `sandboxes_require_verification`: your account isn't fully
            verified.

            - `sandboxes_not_whitelisted`: Sandboxes isn't enabled for your
            organization (invite-only preview); `GET /ai/sandbox-access` tells
            whether it is.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TelnyxErrors'
              example:
                errors:
                  - title: sandboxes_not_whitelisted
                    detail: The organization isn't whitelisted.
        '404':
          description: >-
            Not found (code 10005): the resource doesn't exist or belongs to
            another organization. The detail says what's missing.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TelnyxErrors'
              example:
                errors:
                  - code: '10005'
                    title: Resource not found
                    detail: Sandbox not found.
        '422':
          description: >-
            Validation error: `page[after]` or `Last-Event-ID` isn't a position
            this API returned.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TelnyxErrors'
        '429':
          description: >-
            - `too_many_log_readers`: your organization already has the maximum
            number of log streams open; close one, or retry later.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TelnyxErrors'
              example:
                errors:
                  - title: too_many_log_readers
                    detail: Too many log streams are open for this organization.
        '503':
          description: A dependency can't answer right now (code 10037); retry later.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TelnyxErrors'
              example:
                errors:
                  - code: '10037'
                    title: Service unavailable
                    detail: A dependency can't answer right now; retry later.
components:
  schemas:
    LogStream:
      description: Which output stream a line came from.
      enum:
        - stdout
        - stderr
      type: string
    LogPageRespData:
      description: |-
        A page of stored output, in order. Paged by cursor: pass
        `meta.next_page_after` as `page[after]` for the next page.
      properties:
        data:
          items:
            discriminator:
              mapping:
                gap: '#/components/schemas/LogGap'
                line: '#/components/schemas/LogLine'
              propertyName: type
            oneOf:
              - $ref: '#/components/schemas/LogLine'
              - $ref: '#/components/schemas/LogGap'
          type: array
        meta:
          $ref: '#/components/schemas/CursorMeta'
      required:
        - data
        - meta
      type: object
    TelnyxErrors:
      description: The standard Telnyx error body.
      properties:
        errors:
          description: One or more errors.
          items:
            $ref: '#/components/schemas/TelnyxError'
          type: array
      required:
        - errors
      type: object
    LogGap:
      description: Output that isn't available, reported in place instead of being skipped.
      properties:
        from_ts:
          description: Start of the missing range; `null` when unknown.
          format: date-time
          type:
            - string
            - 'null'
        position:
          description: >-
            Opaque position of the gap; pass it as `page[after]` (or
            `Last-Event-ID`) to continue right after it.
          type: string
        reason:
          $ref: '#/components/schemas/LogGapReason'
          description: >-
            Why the output isn't there: `expired` (past its retention, removed
            from your bucket, or changed there), `log_bucket_unavailable` (your
            log bucket couldn't be written, so the output wasn't stored), or
            `size_cap_reached` (the sandbox's output passed the size cap).
        records:
          description: How many lines are missing; `null` when unknown.
          type:
            - integer
            - 'null'
        stream:
          description: The stream the gap touches; `null` when it touches both.
          anyOf:
            - $ref: '#/components/schemas/LogStream'
            - type: 'null'
        to_ts:
          description: End of the missing range; `null` when unknown.
          format: date-time
          type:
            - string
            - 'null'
        type:
          enum:
            - gap
          type: string
      required:
        - type
        - position
        - reason
        - stream
        - records
        - from_ts
        - to_ts
      type: object
    LogLine:
      description: One line of the sandbox's output.
      properties:
        line:
          description: >-
            The text, without its newline. Lines are cut at 256 KiB, and bytes
            that weren't valid UTF-8 appear as U+FFFD.
          type: string
        position:
          description: >-
            Opaque position of this line; pass it as `page[after]` (or
            `Last-Event-ID`) to continue right after it.
          type: string
        stream:
          $ref: '#/components/schemas/LogStream'
          description: '`stdout` or `stderr`.'
        ts:
          description: When the container runtime wrote the line.
          format: date-time
          type: string
        type:
          enum:
            - line
          type: string
      required:
        - type
        - position
        - ts
        - stream
        - line
      type: object
    CursorMeta:
      description: >-
        Pagination metadata for log reads, which page by cursor. A growing log
        can't be numbered or counted stably, so there's no `page_number`,
        `total_pages` or `total_results`.
      properties:
        next_page_after:
          description: >-
            Value to pass as `page[after]` to get the next page. `null` means
            you have reached the end of the output available so far.
          type:
            - string
            - 'null'
        page_size:
          description: Records per page.
          type: integer
      required:
        - page_size
        - next_page_after
      type: object
    TelnyxError:
      description: One error in the standard Telnyx error body.
      properties:
        code:
          description: >-
            Telnyx error code: a 5-digit string for general errors, e.g.
            `10009`. Sandboxes-specific errors are identified by their name in
            `title`.
          type: string
        detail:
          description: Human-readable explanation.
          type:
            - string
            - 'null'
        meta:
          description: Extra information.
          anyOf:
            - $ref: '#/components/schemas/TelnyxErrorMeta'
            - type: 'null'
        source:
          description: Where the error is.
          anyOf:
            - $ref: '#/components/schemas/TelnyxErrorSource'
            - type: 'null'
        title:
          description: >-
            Short, constant summary of the error. For Sandboxes-specific errors,
            the error's name, e.g. `quota_exceeded`.
          type: string
      required:
        - title
      type: object
    LogGapReason:
      description: Why a range of output isn't available.
      enum:
        - expired
        - log_bucket_unavailable
        - size_cap_reached
      type: string
    TelnyxErrorMeta:
      description: Extra error information.
      properties:
        url:
          default: null
          description: Documentation page for the error code.
          type:
            - string
            - 'null'
      type: object
    TelnyxErrorSource:
      description: Where in the request the error was found.
      properties:
        parameter:
          default: null
          description: Name of the offending parameter.
          type:
            - string
            - 'null'
        pointer:
          default: null
          description: JSON pointer into the request body, e.g. `/timeout`.
          type:
            - string
            - 'null'
      type: object
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer

````