Streaming structured output for TypeScript

schema-stream

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

bun add schema-stream zod
snapshot 0one character per 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.

Parse once. Hand application code an object.

iterate() accepts streaming text or bytes and yields independent, schema-shaped object snapshots. Application code can use each update immediately, without decoding and parsing its own snapshot first.

provider chunk → SchemaStream.iterate() → typed object snapshotonValueComplete → conditional action while the root keeps streaming

Committed Apple M5 Max evidence uses a 2 MiB long-string fixture, 64 KiB source chunks, and five measured samples. It is a parser-path profile, not model or network latency and not a standalone JSON operation claim.

Inspect all fixtures and methodology

One parser boundary. The SDK stays your choice.

See every policy shape the same response.

Open playground
SchemaStream progressively materializing a dashboard from JSON snapshots