Skip to main content

Overview

The AI API provides isolated text generation from within tools, aligned with Vercel AI SDK generateText 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.
Returns: 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).
Returns: Promise<AiGenerateOutput>

Response Shape (AiGenerateOutput)

The full-options response mirrors AI SDK GenerateTextResult:

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)

Use structuredOutput 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

Good context leads to better results
Use simplified for quick text, full options when you need metadata
AI responses may vary — always validate
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

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