Content generation
Create emails, reports, or other prose from supplied instructions.
AI Tools · Function
generateText produces text from a prompt with a language model and can call tools during execution. It is suited to non-interactive tasks such as automation, drafting, summarization, and tool-using agents.
Call generateText with a language model and either a string prompt or a message array. Await its result to access generated text, content, metadata, and other execution details; tools can also be supplied for agent-style workflows.
generateText({ model, prompt, tools? }) => Promise<GenerateTextResult>| Name | Type | Description |
|---|---|---|
model | LanguageModel | The language model used to generate the response. |
prompt | string | Array<SystemModelMessage | UserModelMessage | AssistantModelMessage | ToolModelMessage> | Input text or an array of system, user, assistant, and tool messages. |
tools | ToolSet | Tools available for model-directed tool calls. |
A promise resolving to a result object containing generated text, content, and metadata.
import { generateText } from 'ai';
const { text } = await generateText({
model: 'anthropic/claude-sonnet-5.5',
prompt: 'Summarize the benefits of automated testing in three sentences.',
});
console.log(text);Generates text from a prompt with the selected language model and prints the returned text.
Create emails, reports, or other prose from supplied instructions.
Summarize documents or web-page content in a backend job.
Let a model select and invoke application tools.
streamTextOutput.objecttool calling