Interface GenerateObjectOptions<T>

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"',
};
interface GenerateObjectOptions<T> {
    provider?: string;
    model?: string;
    schema: T;
    schemaName?: string;
    schemaDescription?: string;
    prompt?: string;
    system?: string;
    messages?: Message[];
    temperature?: number;
    maxTokens?: number;
    maxRetries?: number;
    apiKey?: string;
    baseUrl?: string;
}

Type Parameters

  • T extends ZodType

    The Zod schema type that defines the expected output shape.

Properties

provider?: string

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

Example

`"openai"`, `"anthropic"`, `"ollama"`
model?: string

Model identifier. Accepts "provider:model" or plain model name with provider.

Example

`"openai:gpt-4o"`, `"gpt-4o-mini"`
schema: T

Zod schema defining the expected output shape.

schemaName?: string

Human-readable name for the schema, injected into the system prompt to give the model context about what it is generating.

Example

`"PersonInfo"`
schemaDescription?: string

Description of the schema, injected into the system prompt alongside the JSON Schema definition.

Example

`"Information about a person extracted from unstructured text."`
prompt?: string

User prompt. Convenience alternative to building a messages array.

system?: string

System prompt. The schema extraction instructions are appended to this, so any custom system context is preserved.

messages?: Message[]

Full conversation history.

temperature?: number

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

maxTokens?: number

Hard cap on output tokens.

maxRetries?: number

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
apiKey?: string

Override the API key instead of reading from environment variables.

baseUrl?: string

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