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

# Stream process logs in real time

> Streams the stdout and stderr output of a process in real time: the output so far, then live output as the process writes it. Closes when the process exits or the client disconnects.
By default, output is plain text with `stdout:` or `stderr:` prefixes at the start of each source stream's lines. Partial lines (e.g. prompts) are sent without waiting for a newline; their continuations have no new prefix. The other stream is not held back while a line is incomplete, and chronological order across stdout and stderr is not guaranteed.
This format does not provide unambiguous framing: output from the other stream, or a `[keepalive]` marker sent every 30 seconds, can appear inside an unfinished line. A later continuation can therefore lack a prefix identifying its source. Do not rely on this text stream to reconstruct stdout and stderr separately; request NDJSON for source-preserving streaming, or use GET /process/{identifier}/logs for separate output snapshots.
With `Accept: application/x-ndjson`, each line is a JSON object with `type` (`stdout`, `stderr`, `keepalive`, `restart`, `truncated`, or `error`) and optional `data`. Output records retain source identity and original bytes, including partial lines and newlines, for both retained history and live output. For `encoding: "base64"`, decode `data` before concatenating bytes per source; this occurs for binary data or a UTF-8 character split across chunks. Chunk boundaries are arbitrary and ordering is collection order, not a strict chronology across streams.
`keepalive` has no output data. A quiet active stream sends an initial keepalive after attachment so clients can receive the response before sending stdin; subsequent keepalives are sent every 30 seconds. `restart` carries a supervisor restart notice, not process output. `truncated` reports a retention or slow-reader gap and must not be appended to stdout/stderr. `error` reports a streaming failure. The connection ends after the final process exit, including automatic restarts; there is no `result` record. Older processes without structured history return HTTP 409 for NDJSON; their text stream remains available.



## OpenAPI

````yaml /reference/sandbox-api/openapi.json get /process/{identifier}/logs/stream
openapi: 3.0.0
info:
  description: API for manipulating filesystem, processes and network.
  title: Sandbox API
  contact: {}
  version: 0.0.1
servers:
  - url: https://{sandbox_host}
    description: >-
      Host from the sandbox's returned url, without the scheme or trailing
      slash.
    variables:
      sandbox_host:
        default: sandbox.example.com
security:
  - BearerAuth: []
paths:
  /process/{identifier}/logs/stream:
    get:
      tags:
        - process
      summary: Stream process logs in real time
      description: >-
        Streams the stdout and stderr output of a process in real time: the
        output so far, then live output as the process writes it. Closes when
        the process exits or the client disconnects.

        By default, output is plain text with `stdout:` or `stderr:` prefixes at
        the start of each source stream's lines. Partial lines (e.g. prompts)
        are sent without waiting for a newline; their continuations have no new
        prefix. The other stream is not held back while a line is incomplete,
        and chronological order across stdout and stderr is not guaranteed.

        This format does not provide unambiguous framing: output from the other
        stream, or a `[keepalive]` marker sent every 30 seconds, can appear
        inside an unfinished line. A later continuation can therefore lack a
        prefix identifying its source. Do not rely on this text stream to
        reconstruct stdout and stderr separately; request NDJSON for
        source-preserving streaming, or use GET /process/{identifier}/logs for
        separate output snapshots.

        With `Accept: application/x-ndjson`, each line is a JSON object with
        `type` (`stdout`, `stderr`, `keepalive`, `restart`, `truncated`, or
        `error`) and optional `data`. Output records retain source identity and
        original bytes, including partial lines and newlines, for both retained
        history and live output. For `encoding: "base64"`, decode `data` before
        concatenating bytes per source; this occurs for binary data or a UTF-8
        character split across chunks. Chunk boundaries are arbitrary and
        ordering is collection order, not a strict chronology across streams.

        `keepalive` has no output data. A quiet active stream sends an initial
        keepalive after attachment so clients can receive the response before
        sending stdin; subsequent keepalives are sent every 30 seconds.
        `restart` carries a supervisor restart notice, not process output.
        `truncated` reports a retention or slow-reader gap and must not be
        appended to stdout/stderr. `error` reports a streaming failure. The
        connection ends after the final process exit, including automatic
        restarts; there is no `result` record. Older processes without
        structured history return HTTP 409 for NDJSON; their text stream remains
        available.
      parameters:
        - description: Process identifier (PID or name)
          name: identifier
          in: path
          required: true
          schema:
            type: string
        - description: >-
            Explicit application/x-ndjson opts into structured records; absent
            or wildcard Accept retains text/plain. Supported explicit media
            types honor q weights, preferring NDJSON on a tie.
          name: Accept
          in: header
          schema:
            type: string
      responses:
        '200':
          description: Process output as prefixed text or NDJSON records
          content:
            text/plain:
              schema:
                type: string
            application/x-ndjson:
              schema:
                type: string
        '400':
          description: Invalid process identifier
          content:
            text/plain:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
            application/x-ndjson:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '404':
          description: Process not found
          content:
            text/plain:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
            application/x-ndjson:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '409':
          description: Structured history unavailable for this older process
          content:
            text/plain:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
            application/x-ndjson:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '500':
          description: Internal server error
          content:
            text/plain:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
            application/x-ndjson:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
components:
  schemas:
    ErrorResponse:
      type: object
      required:
        - error
      properties:
        error:
          type: string
          example: Error message
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      description: Sandbox access token created through POST /v1/token.

````