Overview
The AI API provides isolated text generation from within tools, aligned with Vercel AI SDKgenerateText semantics. Requests are proxied to a dedicated generation endpoint — they do not go through the agent chat pipeline.
Powerful Tool Enhancement: The AI API lets you embed AI generation directly in your tools with custom personas, multi-modal inputs, and rich response metadata.
Import
Capabilities
Text Generation
Generate content with custom prompts and personas
Image Analysis
Analyze images with AI vision capabilities
Document Processing
Process and analyze documents with AI
Multi-Modal
Combine text, images, and files in one request
Multi-Provider
Google (Vertex AI), OpenAI, and Anthropic models
Web Grounding
Google Search grounding with source URLs
Methods
Simplified: AI.generate(prompt, content?)
Quick text generation. Returns plain text as a string.string
required
When called with one argument, this is the user prompt. When called with two arguments, it becomes the system instruction.
UserContent
User message content. Accepts a string or an array of multimodal parts (
TextPart, ImagePart, FilePart) from the AI SDK.Promise<string>
Full options: AI.generate(options)
Full control over generation parameters. Returns a rich result object.string
Model to use, e.g.
'google/gemini-2.0-flash', 'openai/gpt-4o', 'anthropic/claude-sonnet-4-20250514'. Defaults to the agent’s configured model.string
System instruction.
string
User prompt (simple text).
array
Conversation messages (AI SDK
ModelMessage[]).number
Sampling temperature (0–2).
number
Maximum tokens to generate.
{ schema: JSONSchema7 }
Constrain the model response to a JSON Schema. The parsed object lands on
result.output. Mirrors AI SDK Output.object({ schema }). Object-mode
only — array / choice modes are future extensions.When set on a Google model, the auto-injected google_search tool is
suppressed (Vertex does not allow mixing function-calling tools with
google_search in one request).Promise<AiGenerateOutput>
Response Shape (AiGenerateOutput)
The full-options response mirrors AI SDKGenerateTextResult:
Supported Providers
If the requested provider’s API key is not configured, the request falls back to the default Vertex AI model.
Google models automatically get Google Search grounding — real-time web search results appear in the
sources field of the full-options response.Content Types
Text
Image
File
Complete Examples
Product Description Generator
Weather Search with Google Grounding
Image Analysis Tool
Content Summarizer
Translation Tool
Sentiment Analysis (Structured Output)
UsestructuredOutput to make the model return an object that conforms to a
JSON Schema. The parsed result lands on result.output — no more
JSON.parse(...) and no more “the model wrapped it in markdown again” bugs.
Best Practices
Provide clear, specific context
Provide clear, specific context
Good context leads to better results
Choose the right overload
Choose the right overload
Use simplified for quick text, full options when you need metadata
Handle variable responses
Handle variable responses
AI responses may vary — always validate
Don't use AI for simple logic
Don't use AI for simple logic
Use regular code for deterministic tasks
Common Use Cases
Performance Considerations
Response Time
AI generation typically takes 1-5 seconds. Longer/more complex requests take more time.
Context Length
Maximum context length varies by model. Keep contexts focused and relevant.
Image Processing
Image analysis is slower than text. Optimize image sizes when possible.
Caching
Cache common AI responses. Store frequently requested generations.
Limitations
- Maximum context length varies by model
- Image size limits apply (optimize before sending)
- File types supported: PDF, images, text files
- Response may vary between calls (non-deterministic)
- Some content may be filtered for safety
- Processing time increases with input complexity
Error Handling
Related APIs
User API
Get user context for personalization
Data API
Store AI-generated content
Products API
Enhance products with AI descriptions
Jobs API
Schedule AI generation tasks
See Also
- LuaTool - Creating tools
- Tool Examples - More tool patterns
- User API - Accessing user data

