Skip to main content
Generates a structured, typed object for a given prompt and schema using a language model. This function does not stream the output. If you want to stream the output, use streamObject instead.
generateObject is deprecated. Use generateText with an output setting instead.

Parameters

LanguageModel
required
The language model to use.
FlexibleSchema
The schema of the object that the model should generate. Required unless using output: 'enum' or output: 'no-schema'.
string
Optional name of the output that should be generated. Used by some providers for additional LLM guidance, e.g., via tool or schema name.
string
Optional description of the output that should be generated. Used by some providers for additional LLM guidance, e.g., via tool or schema description.
'object' | 'array' | 'enum' | 'no-schema'
The type of the output.
  • 'object': The output is an object.
  • 'array': The output is an array.
  • 'enum': The output is an enum.
  • 'no-schema': The output is not a schema.
Array<string>
The enum values that the model should use. Required when output: 'enum'.
string
A simple text prompt. You can either use prompt or messages but not both.
Array<CoreMessage>
A list of messages. You can either use prompt or messages but not both.
string
A system message that will be part of the prompt.
number
Maximum number of tokens to generate.
number
Temperature setting. The value is passed through to the provider. The range depends on the provider and model. It is recommended to set either temperature or topP, but not both.
number
Nucleus sampling. The value is passed through to the provider. The range depends on the provider and model. It is recommended to set either temperature or topP, but not both.
number
Only sample from the top K options for each subsequent token. Used to remove “long tail” low probability responses. Recommended for advanced use cases only. You usually only need to use temperature.
number
Presence penalty setting. It affects the likelihood of the model to repeat information that is already in the prompt. The value is passed through to the provider. The range depends on the provider and model.
number
Frequency penalty setting. It affects the likelihood of the model to repeatedly use the same words or phrases. The value is passed through to the provider. The range depends on the provider and model.
number
The seed (integer) to use for random sampling. If set and supported by the model, calls will generate deterministic results.
number
default:"2"
Maximum number of retries. Set to 0 to disable retries.
AbortSignal
An optional abort signal that can be used to cancel the call.
Record<string, string>
Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.
RepairTextFunction
A function that attempts to repair the raw output of the model to enable JSON parsing.
DownloadFunction
Custom download function to use for URLs. By default, files are downloaded if the model does not support the URL for the given media type.
TelemetrySettings
Optional telemetry configuration (experimental).
ProviderOptions
Additional provider-specific options. They are passed through to the provider from the AI SDK and enable provider-specific functionality that can be fully encapsulated in the provider.

Returns

RESULT
The generated object (typed according to the schema).
string | undefined
The reasoning text if the model supports reasoning output.
FinishReason
The reason why the generation finished.
LanguageModelUsage
The token usage of the generated response.
Array<CallWarning>
Warnings from the model provider (e.g., unsupported settings).
LanguageModelResponseMetadata
Response metadata.
LanguageModelRequestMetadata
Request metadata.
ProviderMetadata
Additional provider-specific metadata.
(init?: ResponseInit) => Response
Converts the object to a JSON response.

Examples

Object generation

Array generation

Enum generation