Skip to main content
core-ai provides strongly-typed structured outputs using Zod schemas, ensuring your responses match expected formats with full TypeScript type inference.

Generate Structured Objects

Use generateObject() to get validated JSON responses:

Stream Structured Objects

Stream JSON as it’s being generated:

Object stream events

The streamObject() function returns an ObjectStream — an async iterable with .result and .events. It emits these event types:
The object event is emitted once, when the full object payload has been validated. Use object-delta events for progressive UI updates while JSON is still streaming.

Complex Schema Examples

Schema Descriptions

Add descriptions to help the model understand your schema:

Type Inference

TypeScript automatically infers types from Zod schemas:

Error Handling

Handle validation and parsing errors:

Streaming with UI Updates

Update your UI as the object is built:

Configuration Options

Customize structured output generation:

Best Practices

Help the model understand what you want:
Reduce temperature for more predictable JSON structure:
Build previews from raw JSON chunks, then switch to the validated object when it arrives:
Add custom validation after generation:

Next Steps

Chat Completion

Generate text responses without structure

Tool Calling

Combine structured outputs with tool calls

Streaming

Stream regular text responses

Zod Documentation

Learn more about Zod schemas