Interface: GenerateObjectOptions<T>
Defined in: packages/agentos/src/api/generateObject.ts:117
Options for a generateObject call.
At minimum, schema and either prompt or messages must be supplied.
Provider/model resolution follows the same rules as generateText.
Example
const opts: GenerateObjectOptions<typeof mySchema> = {
schema: z.object({ name: z.string(), age: z.number() }),
prompt: 'Extract: "John is 30 years old"',
};
Type Parameters
T
T extends ZodType
The Zod schema type that defines the expected output shape.
Properties
apiKey?
optionalapiKey:string
Defined in: packages/agentos/src/api/generateObject.ts:188
Override the API key instead of reading from environment variables.
baseUrl?
optionalbaseUrl:string
Defined in: packages/agentos/src/api/generateObject.ts:191
Override the provider base URL (useful for local proxies or Ollama).
fallbackProviders?
optionalfallbackProviders:FallbackProviderEntry[]
Defined in: packages/agentos/src/api/generateObject.ts:198
Ordered fallback providers tried when the primary fails with a retryable
error. When undefined, auto-built from env keys. Pass [] to disable.
See
import('./generateText.js').GenerateTextOptions.fallbackProviders
maxRetries?
optionalmaxRetries:number
Defined in: packages/agentos/src/api/generateObject.ts:185
Number 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.
Default
2
maxTokens?
optionalmaxTokens:number
Defined in: packages/agentos/src/api/generateObject.ts:176
Hard cap on output tokens.
messages?
optionalmessages:Message[]
Defined in: packages/agentos/src/api/generateObject.ts:170
Full conversation history.
model?
optionalmodel:string
Defined in: packages/agentos/src/api/generateObject.ts:132
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"`
onFallback()?
optionalonFallback: (error,fallbackProvider) =>void
Defined in: packages/agentos/src/api/generateObject.ts:203
Called when a fallback provider is about to be tried.
Parameters
error
Error
fallbackProvider
string
Returns
void
policyTier?
optionalpolicyTier:"safe"|"standard"|"mature"|"private-adult"
Defined in: packages/agentos/src/api/generateObject.ts:221
Caller's intended content policy tier. Forwarded to import('./generateText.js').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 NSFW story
extraction tagged with policyTier: 'mature' will pre-empt the
422 by routing to Hermes 3 (which honors the looser
json_object mode that generateObject falls back to for
non-OpenAI providers).
prompt?
optionalprompt:string
Defined in: packages/agentos/src/api/generateObject.ts:154
User prompt. Convenience alternative to building a messages array.
provider?
optionalprovider:string
Defined in: packages/agentos/src/api/generateObject.ts:124
Provider name. When supplied without model, the default text model for
the provider is resolved automatically.
Example
`"openai"`, `"anthropic"`, `"ollama"`
requestTimeout?
optionalrequestTimeout:number
Defined in: packages/agentos/src/api/generateObject.ts:229
Per-call request timeout in milliseconds, forwarded to import('./generateText.js').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.
schema
schema:
T
Defined in: packages/agentos/src/api/generateObject.ts:135
Zod schema defining the expected output shape.
schemaDescription?
optionalschemaDescription:string
Defined in: packages/agentos/src/api/generateObject.ts:151
Description of the schema, injected into the system prompt alongside the JSON Schema definition.
Example
`"Information about a person extracted from unstructured text."`
schemaName?
optionalschemaName:string
Defined in: packages/agentos/src/api/generateObject.ts:143
Human-readable name for the schema, injected into the system prompt to give the model context about what it is generating.
Example
`"PersonInfo"`
system?
optionalsystem:string|SystemContentBlock[]
Defined in: packages/agentos/src/api/generateObject.ts:167
System 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.
temperature?
optionaltemperature:number
Defined in: packages/agentos/src/api/generateObject.ts:173
Sampling temperature forwarded to the provider (0-2 for most providers).