For AI agents: the complete documentation index is available at /hclapi/llms.txt, the full documentation bundle is available at /hclapi/llms-full.txt, and this page is available as Markdown at /hclapi/docs/steps/stream.md.

stream

The stream step terminates pipeline execution and flushes a live data stream to the client. It consumes standard Go iterators (RecordSeq) or raw readers (io.Reader).

route "GET /events" {
  valkey "feed" {
    connection = "broker"
    op         = "subscribe"
    channel    = "audit.logs"
  }

  stream "sse" {
    source    = steps.feed.stream
    event     = "audit"
    heartbeat = "15s"
    retry     = "3s"
  }
}

Supported formats

FormatLabelDefault Content-TypeExpected source type
ssestream "sse"text/event-streamiter.Seq2[any, error]
ndjsonstream "ndjson"application/x-ndjsoniter.Seq2[any, error]
csvstream "csv"text/csv; charset=utf-8iter.Seq2[any, error]
rawstream "raw"configured/octet-streamio.Reader

Attributes

AttributeTypeApplicable formatsDefaultDescription
sourceanyallrequiredContext iterator or reader expression
eventstringsse""SSE event type identifier
heartbeatDurationsse"15s"Periodic comment : heartbeat\n\n interval
retryDurationsse""Client reconnection delay sent as retry: <ms>
flush_everyintndjson1Buffer size before forcing an HTTP network flush
headersmapall{}Custom headers to send with the initial response
content_typestringraw""Custom Media-Type for raw streams
schemaTypeSpecsse, ndjsonnullSchema model used for egress field masking
whenboolalltrueConditional execution guard

Streaming SQL queries

Export database rows as newline-delimited JSON (ndjson) without loading the entire result set into memory:

route "GET /export/transactions" {
  sql "fetch" {
    connection = "primary"
    query      = "SELECT id, amount, timestamp FROM transactions"
    stream     = true
  }

  stream "ndjson" {
    source      = steps.fetch.stream
    flush_every = 100
  }
}

Streaming raw binary or proxy data

Pipe outbound HTTP responses directly to the incoming client connection:

route "GET /download/avatar" {
  http "cdn" {
    url    = "https://cdn.example.com/avatars/user-123.jpg"
    stream = true
  }

  stream "raw" {
    content_type = "image/jpeg"
    source       = steps.cdn.stream
  }
}