Skip to main content

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?

optional apiKey: string

Defined in: packages/agentos/src/api/generateObject.ts:147

Override the API key instead of reading from environment variables.


baseUrl?

optional baseUrl: string

Defined in: packages/agentos/src/api/generateObject.ts:150

Override the provider base URL (useful for local proxies or Ollama).


maxRetries?

optional maxRetries: 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?

optional maxTokens: number

Defined in: packages/agentos/src/api/generateObject.ts:135

Hard cap on output tokens.


messages?

optional messages: Message[]

Defined in: packages/agentos/src/api/generateObject.ts:129

Full conversation history.


model?

optional model: 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?

optional prompt: string

Defined in: packages/agentos/src/api/generateObject.ts:120

User prompt. Convenience alternative to building a messages array.


provider?

optional provider: 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?

optional schemaDescription: 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?

optional schemaName: 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?

optional system: 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?

optional temperature: number

Defined in: packages/agentos/src/api/generateObject.ts:132

Sampling temperature forwarded to the provider (0-2 for most providers).