Interface: GenerateObjectOptions<T>
Defined in: packages/agentos/src/api/generateObject.ts:84
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:147
Override the API key instead of reading from environment variables.
baseUrl?
optionalbaseUrl:string
Defined in: packages/agentos/src/api/generateObject.ts:150
Override the provider base URL (useful for local proxies or Ollama).
maxRetries?
optionalmaxRetries:number
Defined in: packages/agentos/src/api/generateObject.ts:144
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:135
Hard cap on output tokens.
messages?
optionalmessages:Message[]
Defined in: packages/agentos/src/api/generateObject.ts:129
Full conversation history.
model?
optionalmodel:string
Defined in: packages/agentos/src/api/generateObject.ts:98
Model identifier. Accepts "provider:model" or plain model name with provider.
Example
`"openai:gpt-4o"`, `"gpt-4o-mini"`
prompt?
optionalprompt:string
Defined in: packages/agentos/src/api/generateObject.ts:120
User prompt. Convenience alternative to building a messages array.
provider?
optionalprovider:string
Defined in: packages/agentos/src/api/generateObject.ts:91
Provider name. When supplied without model, the default text model for
the provider is resolved automatically.
Example
`"openai"`, `"anthropic"`, `"ollama"`
schema
schema:
T
Defined in: packages/agentos/src/api/generateObject.ts:101
Zod schema defining the expected output shape.
schemaDescription?
optionalschemaDescription:string
Defined in: packages/agentos/src/api/generateObject.ts:117
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:109
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
Defined in: packages/agentos/src/api/generateObject.ts:126
System prompt. The schema extraction instructions are appended to this, so any custom system context is preserved.
temperature?
optionaltemperature:number
Defined in: packages/agentos/src/api/generateObject.ts:132
Sampling temperature forwarded to the provider (0-2 for most providers).