Skip to main content

Interface: StreamObjectOptions<T, K>

Defined in: packages/agentos/src/api/streamObject.ts:79

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',
};

Type Parameters​

T​

T extends ZodType

The Zod schema type defining the expected output shape.

K​

K extends string = string

The array field named by StreamObjectOptions.elements; a call infers it from the name it passes.

Properties​

abortSignal?​

optional abortSignal: AbortSignal

Defined in: packages/agentos/src/api/streamObject.ts:180

Ends the stream when it aborts, forwarded to GenerateTextOptions.abortSignal: the provider's stream stops, the partial-object and element iterations end, and object rejects with the signal's reason.


accountIdOf?​

optional accountIdOf: LlmUsageAccountResolver

Defined in: packages/agentos/src/api/streamObject.ts:215

Names the account of the call, forwarded to GenerateTextOptions.accountIdOf and surfaced on the global LLM usage observer event as accountId.


apiKey?​

optional apiKey: string

Defined in: packages/agentos/src/api/streamObject.ts:169

Override the API key.


baseUrl?​

optional baseUrl: string

Defined in: packages/agentos/src/api/streamObject.ts:172

Override the provider base URL.


customModelParams?​

optional customModelParams: Record<string, unknown>

Defined in: packages/agentos/src/api/streamObject.ts:209

Provider-specific top-level request fields, forwarded to GenerateTextOptions.customModelParams and spread onto the streamed request body with the same rules as there: a fallback leg gets them minus the fields only another vendor accepts.


effort?​

optional effort: string

Defined in: packages/agentos/src/api/streamObject.ts:149

Reasoning depth forwarded to GenerateTextOptions.effort.


elements?​

optional elements: K

Defined in: packages/agentos/src/api/streamObject.ts:128

The name of one top-level array field of schema, whose elements StreamObjectResult.elementStream yields one at a time as each is completed: an element once the next one begins, and the last one once the array's closing bracket arrives, while any field the schema puts after the array is still streaming, or at the latest when the stream ends with text that parses. Each is parsed by the array's element schema; an element that fails it is skipped and counted in StreamObjectResult.skipped. A name that is not a field of the schema holding an array (optional, nullable or with a default included; one behind a transform, a pipe or z.lazy() is not) throws a TypeError at the call, before any request is sent.

Example​

`"sentences"` for `z.object({ sentences: z.array(Sentence) })`

maxAttempts?​

optional maxAttempts: number

Defined in: packages/agentos/src/api/streamObject.ts:192

The most requests the stream's call sends, a first and its retries together; the provider's configured count when left out. Forwarded to GenerateTextOptions.maxAttempts.


maxRetries?​

optional maxRetries: number

Defined in: packages/agentos/src/api/streamObject.ts:166

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

maxTokens?​

optional maxTokens: number

Defined in: packages/agentos/src/api/streamObject.ts:143

Hard cap on output tokens.


messages?​

optional messages: Message[]

Defined in: packages/agentos/src/api/streamObject.ts:137

Full conversation history.


model?​

optional model: string

Defined in: packages/agentos/src/api/streamObject.ts:94

Model identifier. Prefer the plain model name with provider set; the combined "provider:model" string is also accepted.

Example​

`"gpt-4o"` (with `provider: 'openai'`), `"gpt-4o-mini"`

onAttempt()?​

optional onAttempt: (outcome) => void

Defined in: packages/agentos/src/api/streamObject.ts:195

Called after each request the stream's call sent, so a caller can settle the attempts it paid for.

Parameters​

outcome​

AttemptOutcome

Returns​

void


prompt?​

optional prompt: string

Defined in: packages/agentos/src/api/streamObject.ts:131

User prompt.


provider?​

optional provider: string

Defined in: packages/agentos/src/api/streamObject.ts:86

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

Example​

`"openai"`, `"anthropic"`, `"ollama"`

requestTimeout?​

optional requestTimeout: number

Defined in: packages/agentos/src/api/streamObject.ts:186

Per-call request timeout in milliseconds, forwarded to GenerateTextOptions.requestTimeout.


schema​

schema: T

Defined in: packages/agentos/src/api/streamObject.ts:97

Zod schema defining the expected output shape.


schemaDescription?​

optional schemaDescription: string

Defined in: packages/agentos/src/api/streamObject.ts:111

Description of the schema, injected into the system prompt.

Example​

`"A shopping list with a person's name and items."`

schemaName?​

optional schemaName: string

Defined in: packages/agentos/src/api/streamObject.ts:104

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

Example​

`"ShoppingList"`

serviceTier?​

optional serviceTier: "priority" | "default" | "auto" | "flex"

Defined in: packages/agentos/src/api/streamObject.ts:202

OpenAI service tier, forwarded to GenerateTextOptions.serviceTier and sent as service_tier verbatim on the streamed request. No default: OpenAI then serves the request at the project's configured tier. Other providers ignore it.


system?​

optional system: string

Defined in: packages/agentos/src/api/streamObject.ts:134

System prompt. Schema instructions are appended automatically.


temperature?​

optional temperature: number

Defined in: packages/agentos/src/api/streamObject.ts:140

Sampling temperature forwarded to the provider.


thinking?​

optional thinking: false | { budgetTokens: number; }

Defined in: packages/agentos/src/api/streamObject.ts:156

Extended-thinking switch forwarded to GenerateTextOptions.thinking; see GenerateObjectOptions.thinking.