Generation options including the Zod schema, prompt/messages, and optional provider/model overrides.
A promise resolving to the validated object, raw text, usage, and metadata.
When all retries are exhausted without producing valid JSON that passes Zod validation.
When provider resolution fails (missing API key, unknown provider, etc.).
import { z } from 'zod';
import { generateObject } from '@framers/agentos';
const { object } = await generateObject({
model: 'openai:gpt-4o',
schema: z.object({ name: z.string(), age: z.number() }),
prompt: 'Extract: "John is 30 years old"',
});
console.log(object.name); // "John"
console.log(object.age); // 30
Generates a structured object by forcing the LLM to produce JSON matching a Zod schema.
Combines schema-aware prompt engineering with optional provider-native JSON mode and automatic retry-with-feedback to reliably extract typed data from unstructured text.