Optional providerProvider name. When supplied without model, the default text model for
the provider is resolved automatically.
`"openai"`, `"anthropic"`, `"ollama"`
Optional modelModel identifier. Prefer the plain model name with provider set;
the combined "provider:model" string is also accepted.
`"gpt-4o"` (with `provider: 'openai'`), `"gpt-4o-mini"`
Zod schema defining the expected output shape.
Optional schemaHuman-readable name for the schema, injected into the system prompt to give the model context about what it is generating.
`"PersonInfo"`
Optional schemaDescription of the schema, injected into the system prompt alongside the JSON Schema definition.
`"Information about a person extracted from unstructured text."`
Optional promptUser prompt. Convenience alternative to building a messages array.
Optional systemSystem prompt. The schema extraction instructions are appended to this, so any custom system context is preserved.
Accepts a plain string (single system message) or an ordered array of
SystemContentBlock entries. When an array is supplied, caller
cacheBreakpoint flags are preserved on each block and a final
non-cached block is appended with the JSON schema + formatting rules.
This enables Anthropic prompt caching on the stable prefix while letting
the per-call schema vary freely.
Optional messagesFull conversation history.
Optional temperatureSampling temperature forwarded to the provider (0-2 for most providers).
Optional maxHard cap on output tokens.
Optional maxNumber of times to retry when JSON parsing or Zod validation fails. Each retry appends the error details to the conversation so the model can self-correct.
2
Optional apiOverride the API key instead of reading from environment variables.
Optional baseOverride the provider base URL (useful for local proxies or Ollama).
Optional fallbackOrdered fallback providers tried when the primary fails with a retryable
error. When undefined, auto-built from env keys. Pass [] to disable.
Optional onCalled when a fallback provider is about to be tried.
Optional policyCaller's intended content policy tier. Forwarded to GenerateTextOptions.policyTier so structured-output callers get the same policy-aware fallback behavior as plain text callers — mature/private-adult requests auto-route refusals to an uncensored OpenRouter model instead of hard-failing on a content_policy_violation.
Particularly relevant here because OpenAI's strict structured-
output mode (response_format: json_schema) is the most
aggressively-moderated path on the platform; a mature story
extraction tagged with policyTier: 'mature' that the primary
refuses walks on to the tier's uncensored OpenRouter models, which
take the looser json_object mode that generateObject
uses for non-OpenAI providers.
Optional requestPer-call request timeout in milliseconds, forwarded to GenerateTextOptions.requestTimeout. Structured-output callers that emit long strings (e.g. codegen TSX) raise the abort window for this call without slowing the provider's default failover for chat / narration traffic.
Optional maxThe most attempts each generation's call makes, a first and its retries together; the provider's configured
count when left out. A validation retry (maxRetries) is a generation of its own, with its own count. Within one
attempt, a key-scoped failure on a pool of several keys re-sends the same request with the next usable key, at
most once per key, and those sends are not counted.
Optional onCalled once per attempt a generation's call made, with the answer of the attempt's last send (a key hop's earlier answers are not reported), so a caller can settle the attempts it paid for.
Optional abortEnds the call when it aborts: no further attempt or fallback hop starts, and the call rejects with the signal's reason. Forwarded to every attempt's GenerateTextOptions.abortSignal, which hands it to the provider request.
Optional effortReasoning-depth / token-spend control, forwarded to
GenerateTextOptions.effort. On
effort-capable models the provider emits it as output_config.effort
(Anthropic) or reasoning_effort (OpenAI o-series / GPT-5). Dropped on
models that don't support it.
Optional thinkingExtended-thinking switch, forwarded to
GenerateTextOptions.thinking.
false turns thinking off with the model's own off shape (Sonnet 5.5
takes between_tools, at effort high or below); Opus 5.5, Fable and
Mythos always think. Omitted keeps the model's default, which is thinking
on for Opus 5 and later, Sonnet 5 and later, Fable and Mythos. Thinking
tokens count toward maxTokens, so a structured call on a thinking model
needs room for both.
Optional cachePer-call prompt-cache control, forwarded to
GenerateTextOptions.cache.
false opts this call out of ALL cache marking (the schema block's
marker included — right for one-shot extractions); { ttl: '1h' } puts
a 1-hour TTL on the provider's auto markers (the moving message-tail).
Optional ttl?: "5m" | "1h"Optional schemaTTL for the schema block's own cache marker (the block this call appends
after the caller's system). The schema bytes are stable per call SITE, so
sites whose calls gap more than 5 minutes (human-paced pipelines, slow
loops) should set '1h' — otherwise the entry expires between calls and
every call re-writes the prefix at the write premium. Defaults to the
5-minute marker (previous behavior). Ignored when cache is false.
Optional sessionPer-conversation affinity key, forwarded to
GenerateTextOptions.sessionId.
OpenRouter emits it as session_id for provider sticky routing —
upstream prompt caches are host-scoped, so a load-balanced multi-call
pipeline otherwise cold-misses the cache a prior call wrote on a
different host. Pass a stable id per logical session (blueprint/build
id for codegen loops, conversation id for chat extraction). Providers
without an affinity concept ignore the field.
Optional serviceOpenAI service tier, forwarded to GenerateTextOptions.serviceTier and sent as service_tier
verbatim on every attempt, a validation retry included. No default: OpenAI then serves the request at the
project's configured tier. 'flex' bills at about batch rates but can answer 429 under load; 'priority' is a
paid tier. Other providers ignore it.
Optional customProvider-specific top-level request fields, forwarded to GenerateTextOptions.customModelParams and
spread onto every attempt's request body, a validation retry included, with the same rules as there: a fallback
leg gets them minus the fields only another vendor accepts (OpenRouter's routing controls, Gemini's request
fields, OpenAI's response_format, Anthropic's output_config), and keys collide last-wins with the typed fields at the provider layer. A passthrough tool_choice, tools or response_format here can change the
structured-output route this call takes (generateObject).
Optional sourceOpt-in source label forwarded to GenerateTextOptions.source and surfaced on the global LLM usage observer event. Hosts tag their cost/telemetry rows with it (e.g. 'codegen_tool', 'narrator_state_extractor') — without it every structured-output call rolls up under the generic surface bucket.
Optional budgetA spend budget for this call and, when the same SpendBudget instance is passed to several calls, for all of them: each attempt's provider call is checked against what is left before it is made and recorded after it, so a refused attempt ends the call with no further attempt.
Options for a generateObject call.
At minimum,
schemaand eitherpromptormessagesmust be supplied. Provider/model resolution follows the same rules as generateText.Example