Getting Started
Installation
Version 4 requires Zod 4 and OpenAI 6. The lower-level schema-stream package continues to support both Zod 3.25 and Zod 4.
Progressive streaming
Progressive chunks represent recursively partial z.input<T>. Nested fields may be missing, primitive placeholders may be null, and transforms have not run. The completed input is validated before the generator finishes; parser, source-stream, and final ZodError failures propagate to the consumer.
OpenAI structured outputs
JSON_SCHEMA uses OpenAI's current structured-output payload:
The schema comes from Zod 4's native z.toJSONSchema input conversion. Object schemas are recursively closed for OpenAI strict mode. Unrepresentable Zod types throw during parameter construction, and schemas must still fit OpenAI's supported JSON Schema subset.
Response modes
| Mode | Behavior |
|---|---|
JSON_SCHEMA | Current OpenAI structured outputs |
TOOLS | Function tool calling while preserving existing tools |
JSON | Older JSON object mode plus a schema prompt |
MD_JSON | Schema prompt with markdown-compatible parsing |
THINKING_MD_JSON | Existing thinking-tag/markdown compatibility mode |
FUNCTIONS | Deprecated OpenAI functions compatibility |
Prefer JSON_SCHEMA or TOOLS. The legacy modes remain explicit compatibility surfaces and are not silently redirected.
Migration from 3.x
- Upgrade to Zod 4 and OpenAI 6.
- Remove
zod-to-json-schema. - Treat streamed values as
ZodStreamChunk<T>, notPartial<z.output<T>>. - Update
JSON_SCHEMAmiddleware and snapshots fortype: "json_schema". - Pass an explicit client to
createAgentand handle final validation errors.