AI.generate runs one model call with a prompt you supply and returns the text or the full result. The call skips the agent’s persona, skills, and processors; to run a whole turn of an agent, use Agents.invoke. Available in tools, jobs, webhooks, triggers, processors, and workflow code steps.
Verified against lua-cli 3.33.0.
Quick example
The short form returns text; the options form returns the full result.Methods
generate(prompt, content?)
Generates text and returns it as a string.string
required
The user prompt when called alone. When
content is given, the system instruction instead.UserContent
The user message: a string, or an array of AI SDK v5 parts. Parts are
{ type: 'text', text }, { type: 'image', image, mediaType? }, and { type: 'file', data, mediaType, filename? }, where image and data are a URL string, a base64 string, or a Buffer.text on the options form.
Example
generate(options).
generate(options)
Generates text with explicit model settings and returns the full result.string
default:"alibaba/qwen3.8-flash"
A model code in
provider/model form, as listed by lua models list. Defaults to the platform default model, not to the agent’s model. A code the platform doesn’t approve falls back to the default.string
System instruction.
string
Plain user prompt. Pass
prompt or messages, not both.ModelMessage[]
AI SDK v5 messages,
{ role, content }, with the same part shapes as content on the short form. The server validates them; a malformed part is rejected with a 400 that names its path, such as messages[0].content[1].number
Sampling temperature. The accepted range is the provider’s.
number
Maximum number of tokens to generate.
{ schema: AiGenerateJsonSchema }
A JSON Schema the response must match; the parsed object lands on
output. The schema needs a top-level type: "object". On Google models, setting it turns Google Search grounding off for that call.AiGenerateOutput
Optional fields are omitted when empty.
Error:
- Invalid input:
structuredOutput.schema must be a JSON Schema with top-level type "object", or a malformedmessagespart. Fix the request; retrying doesn’t help. - The provider refused the request as sent (a model the provider doesn’t serve, a refused prompt): the platform reports it as
PROVIDER_REJECTEDwithtransient: false. Retrying unchanged fails the same way. - The provider is unavailable (408, 429, 5xx, or no answer): the platform retries on the next model in its fallback chain. When every model fails, a deployed agent sees
Every model in the fallback chain failed;lua testsees the platform’sUPSTREAM_UNAVAILABLEerror,… is temporarily unavailable — retry in a moment. - No message from the server:
AI generation failed.
Types
AiGenerateInput, AiGenerateOutput, AiGenerateStructuredOutput, AiGenerateJsonSchema (a Record<string, unknown>), AiGenerateSource, AiGenerateToolCall, and AiGenerateToolResult are exported from lua-cli. UserContent, ModelMessage, FinishReason, LanguageModelUsage, ReasoningOutput, and CallWarning are the AI SDK v5 types of the same names; you don’t need to import them to call AI.generate.
See also
Agents— run a full turn of an agent instead of a bare model callCDN— read stored files intoimageandfileparts- About models — model codes, the platform default, and
lua models list - Compose agents — when to use
AI.generateand when to invoke an agent

