Explore topics

Topic

AI SDK Examples

Every example here is a complete implementation — API route, client component, and the SDK call in context — not a snippet. Start with the core functions (generateText, streamText, generateObject), then move into the Agent API: loop control with stopWhen, context trimming with prepareStep, structured agent output, and tool-call repair. Examples track the current AI SDK release, with version notes where behavior changed.

69 patterns7 featured

AI SDK version notes

These examples track the current AI SDK release. Prefer the Agent API (`ToolLoopAgent`, `stopWhen`, `prepareStep`) over one-off versioned landing pages — version URLs rot as soon as the next major ships.

If you are migrating from older AI SDK majors: structured output moved toward `Output.object()` / schema-first helpers, agent loops expose explicit stop conditions (`stopWhen`, `stepCountIs`), and tool-call repair is a first-class recovery path when the model emits malformed arguments. Open the featured Agent API patterns below for the working shape; skim the pattern READMEs for breaking-change callouts.

Featured patterns

A curated starting point for this topic — open a live preview, then adapt the source.

7 curated

More patterns

Additional patterns that fit this topic.

62 more
01
HIL Tool Approval BasicChat assistant with human approval workflows for safe tool execution.
02
HIL Agentic Context BuilderBuild brand context through AI-guided questioning and web research. Gathers insights to create detailed brand profiles.
03
Prompt UI ImproverTransform short, vague UI requests into production-grade design briefs with strong visual, interaction, and implementation detail.
04
AI SDK Gemini Flash TextGenerate text and analyze market research using Google's Gemini 2.5 Flash. Includes interactive charts and data visualization.
05
AI SDK Nano Banana ImageGenerate images using Gemini 3.1 Flash Lite Image with prompt optimization. Includes style adaptation and customizable parameters.
06
AI SDK Nano Banana Image EditGenerate and edit images using Nano Banana 2.5 Flash. Create new images from text or edit existing ones with natural language. Includes version history and image comparison.
07
AI SDK Nano Banana Image MergeGenerate, edit, and merge images using Nano Banana 2.5 Flash. Create new images from text, edit existing ones with natural language, or merge two images together. Includes version history and image comparison.
08
HIL Needs ApprovalDemonstrate tool approval with async generators. Includes real-time feedback, approval workflows, and interactive management.
09
Tool Input Lifecycle HooksExplore tool input lifecycle hooks: onInputStart, onInputDelta, and onInputAvailable. See how to track tool input generation in real-time during streaming.
10
Preliminary Tool ResultsReturn preliminary tool results using async iterables. Stream status updates during tool execution before the final result is available.
11
Tool API ContextPass arbitrary context from generateText/streamText to tool execution via experimental_context. Access context in tool execute functions for dynamic behavior.
12
Dynamic ToolCreate dynamic tools with runtime-generated schemas using dynamicTool. Demonstrates unit conversion tools where schema adapts based on conversion type (temperature, length, weight, currency) and supports dynamic model selection.
13
Structured Agent Output: Output.choiceDemonstrate structured agent outputs using ToolLoopAgent with Output.choice. Constrain agent outputs to predefined choices for predictable, type-safe responses.
14
Call Options: prepareCallDynamically configure one ToolLoopAgent per request with callOptionsSchema and prepareCall. A customer-support agent rewrites instructions, gates tools, tunes reasoning effort, and injects RAG context based on account tier and urgency.
15
Tool Context: experimental_contextInject request-scoped context (user identity, database handles, session) into ToolLoopAgent tools via experimental_context, so the model never supplies sensitive identity in tool inputs.
16
Chat-Base CloneA comprehensive Chatbase clone demo with widget interface, model selection, web search integration, and human-in-the-loop tool approval workflows.
17
AI Form GeneratorDescribe a form in plain words and get a working, validated form plus the Zod schema behind it. The model returns a typed field list, so no generated code is ever executed.
18
Branding AgentEnter a brand URL to extract colors, typography, and page copy with Firecrawl. A grounded ToolLoopAgent then checks contrast, generates palette variations, and describes writing voice from the scraped page.
19
Brand Product Placement Generator (Nano Banana)Paste a website URL to extract brand signals with Firecrawl, generate a structured product photography brief, auto-create four Nano Banana placement images, and click any result into a local edit flow.
20
Brand Mood Board GeneratorPaste a website URL to extract brand signals with Firecrawl, generate a structured mood-scene brief for abstract and environmental imagery, auto-create four brand-world images, and click any result into a local edit flow.
21
Brand Guidelines Image GeneratorPaste a website URL to extract brand signals with Firecrawl, generate a structured brand-standards brief, render manual-style spreads (color, typography, grid, photography, and more), and refine any image with edit instructions.
22
Competitor Research AgentEnter a competitor URL to get a research brief grounded in their own site. Firecrawl maps and scrapes up to four pages, every extracted fact is checked against the scraped text, and an agent adds positioning, gaps, and a sales battle card with quoted evidence.
23
Data Analysis AgentUpload CSV or JSON data and get AI-powered analysis with interactive visualizations. Detect patterns, correlations, outliers, and generate insights with confidence scores. Export comprehensive reports.
24
Accessibility Audit AgentScan a page's HTML for common accessibility gaps (alt text, headings, links, forms, landmarks). Firecrawl scrapes the page; deterministic checks score and list fixes. Optional agent tools read the same scraped context.
25
SEO AuditAudit any website for on-page SEO issues using Firecrawl. Scrapes a URL, then renders a full-screen report analyzing meta tags, content structure, links, keywords, and schema markup with exportable reports.
26
Marketing agent with skills + readFileChat UI wired to a ToolLoopAgent that loads filesystem skills and exposes readFile on the skill sandbox—demo includes ad-creative, copywriting, and paid-ads skill packs for campaign workflows.
27
Reddit Product Validation AgentValidate startup ideas with a two-phase workflow: discover relevant subreddits, then analyze pain points, existing solutions, willingness to pay, demand trends, and early adopters. Get a go/no-go scorecard with actionable insights.
28
AI Wizard Brand StrategyA full-screen AI levee interface where each stage is an adaptive interview with lock-based progression and dynamic tool-driven prompts.
29
Firecrawl Brand PDFGenerate structured brand brief PDFs from any website URL using Firecrawl branding extraction and JSON Render PDF streaming.
30
Firecrawl Landing Page Teardown PDFGenerate a conversion-focused landing page teardown PDF using one landing URL plus 2-5 competitor URLs.
31
Jev Composite ScorecardScore a pull request description with three atomic Jev score questions, then combine the answers with weights in code.
32
Jev Output VerifierWrite an answer, then show it only if Jev is at least 90% sure it actually answers the question. If not, rewrite once.
33
Jev Loop BreakerLook up facts one step at a time. Stop when Jev is at least 90% sure the notes answer the task, or after 3 lookups.
34
Jev Sub-agent DelegationPick one specialist with a Jev choice, then run only that agent when confidence and selected probability both clear their floors.
35
Jev Best-of-N JudgeThree prepared replies sit on the table. A Jev choice lifts the winner only when its probability clears 0.70.
36
Jev Infinite FAQA FAQ whose last row is a live ask field. Jev opens a canned answer when it matches, or a short grounded answer becomes another row.
37
Jev Tool PermissionsPrune an agent's tool list before the model sees it. Allow and deny rules run first; Jev asks one relevance boolean per remaining tool in a single call.
38
Code Mode CompareSee if stock covers an open order. The model writes one program that calls both lookups and subtracts.
39
Jev Email TagsTag a closed inbox with one Jev boolean per tag. A stamp lands only when its probability clears a floor.
40
Jev Table QueryFilter or sort a closed table with one Jev question per row. A column name never leaves the app.
41
Jev MemoryLong-term agent memory with three Jev gates. Keep durable facts, recall what fits a token budget, and evict what went stale. Nothing is rewritten.
42
Jev + Web ContextExa finds live evidence, Jev answers the same question with and without it, and leave-one-out weights show what each source changed.
43
Jev EvalsRun a rubric eval suite with jev-evals: one Jev call per case answers every rubric, and a baseline diff catches fractional regressions.
44
Generate Speech (OpenAI)Convert text to speech using OpenAI's API. Includes multiple voices, speed control, and real-time playback for voiceovers and accessibility.
45
Transcribe Audio (OpenAI)Transcribe audio files using OpenAI's API. Includes real-time transcription and language detection.
46
Streaming Structured OutputStream structured output from AI prompts in real-time using streamText with Output.object(). Generate typed data with useObject and live rendering.
47
Claude Structured OutputGenerate structured output from AI prompts using Anthropic Claude. Create typed data with generateText and Output.object().
48
Gemini Structured OutputGenerate structured output from AI prompts using Google Gemini. Create typed data with generateText and Output.object().
49
Generate Image (OpenAI)Generate images from text prompts using OpenAI's GPT Image 2.5 Sunburst through the Vercel AI Gateway.
50
Generate Image (Flux)Generate images from text prompts using Flux through the Vercel AI Gateway. Fast, high-quality image generation with one API key.
51
Generate Image (Grok Imagine)Generate images from text prompts using xAI Grok Imagine through the Vercel AI Gateway.
52
Generate Image (Google Gemini)Generate images from text prompts using Google Gemini's image model.
53
Generate Speech (ElevenLabs)Convert text to speech using ElevenLabs API. Includes multiple voices and high-quality audio generation.
54
Transcribe Audio (ElevenLabs)Transcribe audio files using ElevenLabs API. Includes real-time transcription and language detection.
55
Search - Exa AI (robust)Search the web using Exa's semantic API and real-time crawling. Includes URL search, content extraction, Wikipedia, Reddit, and news search tools.
56
Search - Firecrawl (robust)Search the web using Firecrawl's API and real-time crawling. Includes URL search, content extraction, Wikipedia, Reddit, and news search tools.
57
Scrape - Cheerio (lightweight)Scrape websites using Cheerio's fast HTML parser. Includes URL scraping, website crawling, and content extraction without external API costs.
58
Scrape - Jina AI (advanced)Scrape websites using Jina AI's reader service with JavaScript rendering. Includes URL scraping, website crawling, and content extraction with AI-powered parsing.
59
Scrape - Markdown.new (free)Scrape websites using Cloudflare's markdown.new service. Extract clean markdown content from any URL. No API key required.
60
Jev Action GateOne command at a time. It passes the gate only when a Jev boolean clears 0.90.
61
Jev Confidence RouterFour trays are on the table. A message flies to a team only when confidence and the selected probability both clear their floors.
62
Jev Search FilterFilter a closed catalog with one Jev boolean per item. Matches rise out of the pile when their probability clears a floor.

Related topics

Continue with adjacent topics that share the same building blocks.

Browse by category

Jump into the catalog filtered by category.

You’ve reached the end of AI SDK Examples.