Streaming structured output for TypeScript

schema-stream

Typed, schema-shaped JSON snapshots while the response is still arriving.

bun add schema-stream zod
snapshot 0parsing every chunk
{
  "checks": [
    {
      "label": "",
      "state": ""
    }
  ],
  "metrics": {
    "score": null
  },
  "summary": "",
  "title": ""
}

Use the fields that are ready. Keep streaming the rest.

01

Accept arbitrary text and UTF-8 chunk boundaries from provider streams.

02

Materialize typed snapshots according to an explicit emission policy.

03

React once when nested keys or values complete, without rescanning the tree.

Keep parser state. Do not reparse the growing prefix.

SchemaStream consumes each incoming chunk against the parser state it already has. It materializes independent object snapshots only at the cadence your application chooses, then hands those objects directly to application code.

provider chunk → SchemaStream.iterate() → typed object snapshotsnapshotPolicy → control materialization and update frequency
See how the approach works
  1. 01
    Arbitrary chunks arrive

    UTF-8, strings, tokens, and nested values may split anywhere.

  2. 02
    State advances once

    The tokenizer and parser continue from the previous boundary.

  3. 03
    Your code receives an object

    Render a snapshot or react when a completed value matters.

One parser boundary. The SDK stays your choice.

See every policy shape the same response.

Open playground