Interface StreamObjectOptions<T>

Options for a streamObject call.

Shares the same shape as GenerateObjectOptions from generateObject. At minimum, schema and either prompt or messages must be supplied.

Example

const opts: StreamObjectOptions<typeof mySchema> = {
schema: z.object({ name: z.string(), items: z.array(z.string()) }),
prompt: 'List 3 fruits with a person name',
};
interface StreamObjectOptions<T> {
    provider?: string;
    model?: string;
    schema: T;
    schemaName?: string;
    schemaDescription?: string;
    prompt?: string;
    system?: string;
    messages?: Message[];
    temperature?: number;
    maxTokens?: number;
    maxRetries?: number;
    apiKey?: string;
    baseUrl?: string;
}

Type Parameters

  • T extends ZodType

    The Zod schema type defining the expected output shape.

Properties

provider?: string

Provider name. When supplied without model, the default text model for the provider is resolved automatically.

Example

`"openai"`, `"anthropic"`, `"ollama"`
model?: string

Model identifier. Accepts "provider:model" or plain model name with provider.

Example

`"openai:gpt-4o"`, `"gpt-4o-mini"`
schema: T

Zod schema defining the expected output shape.

schemaName?: string

Human-readable name for the schema, injected into the system prompt.

Example

`"ShoppingList"`
schemaDescription?: string

Description of the schema, injected into the system prompt.

Example

`"A shopping list with a person's name and items."`
prompt?: string

User prompt.

system?: string

System prompt. Schema instructions are appended automatically.

messages?: Message[]

Full conversation history.

temperature?: number

Sampling temperature forwarded to the provider.

maxTokens?: number

Hard cap on output tokens.

maxRetries?: number

Number of retries on validation failure. Unlike generateObject, streaming retries are not currently supported (the stream is consumed once). This field is accepted for API symmetry but is unused; validation errors on the final object throw immediately.

Default

0
apiKey?: string

Override the API key.

baseUrl?: string

Override the provider base URL.