Explore Topics
Topic
39 patterns

AI SDK v6

AI SDK v6 introduces the Agent() API, enhanced structured output, and advanced tool patterns. Browse production-ready examples showcasing the latest features.

39 patterns total

All Patterns

Agent Routing Pattern preview

Route user queries to specialized AI agents based on context and intent. Includes dynamic agent selection, load balancing, and fallback handling.

Problems Solved

  • Route user queries to specialized AI agents based on context and intent
  • Dynamic agent selection via generateObject classification
  • Model selection based on query complexity (simple vs complex)
  • Streaming responses with custom data parts for classification metadata
  • 7 specialized agent configs (general, product, technical, sales, billing, etc.)
  • Load balancing and fallback handling across multiple providers

Use Cases

  • Customer service request routing
  • Technical support ticket classification
  • Sales inquiry qualification
  • Multi-department request handling
  • Intent-based agent orchestration
  • Support desk automation
APIsgenerateObjectstreamTextconvertToModelMessagesnew Agenttool(stepCountIs
Servicesopenaiperplexitydeepseek
Tagsaiagentsroutingai-sdk
HIL Tool Approval Basic preview

Chat assistant with human approval workflows for safe tool execution.

Problems Solved

  • Human approval workflows for AI tools
  • Safe AI tool execution with oversight
  • Interactive chat interface with streaming
  • Rate limiting and abuse prevention
  • Tool categorization and management
  • Real-time approval feedback
  • Type-safe tool processing
  • Modular component architecture

Use Cases

  • Content moderation with human oversight
  • E-commerce shopping cart approval
  • User registration management
  • Payment processing workflows
  • Weather information services
  • Safe AI tool execution patterns
  • Human-AI collaboration interfaces
  • Approval workflow management
APIsstreamTextgatewaystepCountIsconvertToModelMessagestool(tools:
Servicesopenai
Tagsaihuman-in-the-loopai-sdktool-approvalchat-interfacerate-limitingsafe-aiworkflow-management
Parallel Processing Pattern preview

Process content with multiple AI agents running simultaneously. Demonstrates concurrent analysis for faster results.

Problems Solved

  • Concurrent content analysis from multiple perspectives
  • Parallel AI processing for faster results
  • Multi-agent AI system demonstration
  • Comprehensive content analysis workflows
  • Efficient resource utilization in AI processing

Use Cases

  • Content analysis from multiple perspectives
  • Research assistance and comprehensive analysis
  • Business intelligence and document review
  • Educational content for parallel processing concepts
  • Quality assurance and content validation
  • Decision support with multiple viewpoints
APIsgenerateText
Servicesopenai
Tagsaiparallel-processingai-agentsserver-actionscontent-analysisdemo
AI SDK Gemini Flash Text preview

Generate text and analyze market research using Google's Gemini 2.5 Flash. Includes interactive charts and data visualization.

Problems Solved

  • AI-powered text generation and analysis
  • Comprehensive market research with web search
  • Interactive data visualization and charts
  • Time-series data analysis and trends
  • Key metrics and KPI identification
  • Source attribution and research validation
  • Rate limiting to prevent API abuse
  • Professional market research reports

Use Cases

  • Market research and analysis
  • Business intelligence and reporting
  • Data visualization and charting
  • Trend analysis and forecasting
  • Competitive research and analysis
  • Investment research and due diligence
  • Academic research and data analysis
  • Content creation with data insights
APIsgenerateTextgenerateObjecttools:
Servicesgoogle
Tagsgoogletext-generationmarket-researchgeminiaivercel-ai-sdkrate-limitingdata-visualizationchartsinteractive
AI SDK Gemini Flash Image  preview

Generate images using Google's Gemini 2.5 Flash with prompt optimization. Includes style adaptation and customizable parameters.

Problems Solved

  • AI-powered image generation using text prompts
  • Rate limiting to prevent API abuse
  • Comprehensive error handling with user feedback

Use Cases

  • AI image generation from text prompts
  • AI-powered creative tools
  • Content creation and design
  • Marketing and advertising visuals
  • Social media content generation
  • Creative project visualization
APIsgenerateTextgenerateImage
Servicesgoogle
Tagsgoogleimage-generationgeminivercel-ai-sdkrate-limiting
AI SDK Gemini Flash Image Edit preview

Generate and edit images using Google's Gemini 2.5 Flash. Create new images from text or edit existing ones with natural language. Includes version history and image comparison.

Problems Solved

  • AI-powered image generation using text prompts
  • AI-powered image editing with natural language
  • Peak React performance with useReducer state management
  • Version history and image comparison functionality
  • Rate limiting to prevent API abuse
  • Comprehensive error handling with user feedback
  • Interactive editing workflow with undo/reset functionality
  • Custom hooks for maintainable state management
  • O(1) version lookups with refs for optimal performance

Use Cases

  • AI image generation from text prompts
  • AI-powered image editing and modification
  • Version history and image comparison workflows
  • High-performance React applications
  • Creative tools and design workflows
  • Content creation and design
  • Marketing and advertising visuals
  • Social media content generation
  • Creative project visualization
  • Iterative design processes
  • Performance-critical image editing applications
APIsgenerateTextgenerateImagegateway
Servicesgoogle-ai
Tagsaiimage-generationimage-editinggooglegeminivercel-ai-sdkrate-limitingperformanceuseReducerversion-historyimage-comparisoncustom-hooks
AI SDK Gemini Flash Image Merge preview

Generate, edit, and merge images using Google's Gemini 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.

Problems Solved

  • AI-powered image generation using text prompts
  • AI-powered image editing with natural language
  • AI-powered image merging from two source images
  • Version history and image comparison functionality
  • Rate limiting to prevent API abuse
  • Comprehensive error handling with user feedback
  • Interactive editing workflow with undo/reset functionality
  • Custom hooks for maintainable state management

Use Cases

  • AI image generation from text prompts
  • AI-powered image editing and modification
  • AI-powered image merging and composition
  • Version history and image comparison workflows
  • Creative tools and design workflows
  • Content creation and design
  • Marketing and advertising visuals
  • Social media content generation
  • Creative project visualization
  • Iterative design processes
APIsgenerateTextgateway
Servicesgoogle-ai
Tagsaiimage-generationimage-editingimage-merginggooglegeminivercel-ai-sdkrate-limitingversion-historyimage-comparisoncustom-hooks
Multi-Step Tool Pattern preview

Execute multi-step workflows with typed tools. Includes streaming, tool chaining, and decision-making for automated tasks.

Problems Solved

  • Complex problem solving with multi-step reasoning using AI SDK v6
  • Real-time web search and news integration with strongly typed tools
  • Iterative AI agent workflows with Experimental_Agent
  • Tool-based AI agent patterns with full type safety
  • Research and analysis automation with streaming support
  • Modern AI agent development with UIToolInvocation pattern

Use Cases

  • Research and analysis tasks with real-time data
  • Market research and trend analysis
  • Technical problem solving with multi-step reasoning
  • News monitoring and analysis
  • Multi-step decision making with AI agents
  • Modern AI agent development patterns
  • Strongly typed tool integration
APIsnew Agenttool(stepCountIsgenerateObjectExperimental_Agenttools:gatewayhasToolCall
Servicesperplexityopenaihackernews
Tagsaiagentstoolsmulti-stepweb-searchnewsanalysisai-sdk-v5strongly-typedstreaming
Orchestrator-Worker Pattern preview

Coordinate multiple worker agents for project management. Handles task distribution, progress tracking, and result synthesis.

Problems Solved

  • Complex project coordination through specialized workers using AI SDK v6
  • Automated project planning and task assignment with strongly typed tools
  • Real-time progress tracking and issue resolution with Experimental_Agent
  • Orchestrator-Worker pattern implementation with full type safety
  • Project lifecycle management with deliverable tracking
  • Modern AI agent coordination patterns with UIToolInvocation

Use Cases

  • Complex project management and coordination
  • Multi-disciplinary team task assignment
  • Software development project orchestration
  • Product development lifecycle management
  • Research project coordination
  • Quality assurance and deliverable tracking
  • Modern AI agent coordination patterns
APIsnew Agenttool(stepCountIsExperimental_Agenttools:gateway
Servicesopenai
Tagsaiagentsorchestratorworkerproject-managementcoordinationai-sdk-v5strongly-typedstreamingdeliverables
Evaluator-Optimizer Pattern preview

Improve output quality with dual agents. Evaluator analyzes quality while optimizer refines results through iterative feedback.

Problems Solved

  • Quality assurance through systematic evaluation and optimization using AI SDK v6
  • Single orchestrator agent coordinating specialized evaluator and optimizer tools
  • Automated content quality assessment with strongly typed tools
  • Iterative content improvement based on evaluation feedback
  • Error recovery and self-improvement capabilities with Experimental_Agent
  • Quality threshold management and optimization strategies
  • Modern AI agent quality control patterns with UIToolInvocation

Use Cases

  • Content quality assurance and optimization
  • Professional writing and documentation
  • Translation and localization quality control
  • Marketing copy optimization
  • Technical documentation review
  • Creative writing enhancement
  • Quality control for AI-generated content
APIsnew Agenttool(stepCountIsExperimental_Agenttools:gateway
Servicesopenai
Tagsaiagentsorchestratorevaluatoroptimizerquality-assurancecontent-optimizationai-sdk-v5streamingerror-recoverytool-coordination
HIL Needs Approval preview

Demonstrate tool approval with async generators. Includes real-time feedback, approval workflows, and interactive management.

Problems Solved

  • Tool approval patterns with async generator workflows
  • Real-time feedback during tool execution
  • Interactive tool management and approval workflows
  • Safe AI tool execution with user oversight
  • Async generator pattern demonstration
  • Tool execution state management
  • Approval workflow visualization
  • Modern AI agent tool patterns

Use Cases

  • Tool approval workflow demonstrations
  • Safe AI tool execution patterns
  • Interactive tool management interfaces
  • Approval workflow implementations
  • Async generator pattern examples
  • Real-time tool execution feedback
  • Educational AI agent patterns
  • Tool execution state management
APIsnew Agenttool(stepCountIsExperimental_Agenttools:gatewayUIToolInvocation
Servicesgoogle-ai
Tagsaiagentstool-approvalasync-generatorapproval-patternsai-sdk-v5streamingreal-time-feedbacktool-executionworkflow-management
HIL Inquire Multiple Choice preview

Gather information through AI-driven multiple choice questions. Includes approval workflows and real-time rendering.

Problems Solved

  • Interactive multiple choice question workflows
  • Structured information gathering through AI questioning
  • Approval-based tool execution patterns
  • Real-time question rendering and user interaction
  • Brand context building through strategic questioning
  • Tool approval workflows with user oversight
  • Multiple choice question UI components
  • AI agent question flow management

Use Cases

  • Brand context building through strategic questioning
  • Interactive surveys and questionnaires
  • User preference gathering and analysis
  • Marketing research and customer insights
  • Educational assessment tools
  • Customer onboarding workflows
  • Market research data collection
  • User experience research
APIsnew Agenttool(stepCountIsvalidateUIMessagesuseChatInferAgentUIMessage
Servicesopenai
Tagsaihuman-in-the-loopmultiple-choiceinteractive-questionsapproval-workflowsai-sdkbrand-contextstrategic-questioningtool-approvalstreaming
HIL Inquire Text Input preview

Gather detailed information through AI-driven text input questions. Includes approval workflows and real-time rendering.

Problems Solved

  • Interactive text input question workflows
  • Structured information gathering through AI questioning
  • Approval-based tool execution patterns
  • Real-time question rendering and user interaction
  • Brand context building through strategic questioning
  • Tool approval workflows with user oversight
  • Text input question UI components
  • AI agent question flow management
  • Open-ended question processing
  • Detailed user response collection

Use Cases

  • Brand context building through strategic questioning
  • Interactive surveys and questionnaires
  • User preference gathering and analysis
  • Marketing research and customer insights
  • Educational assessment tools
  • Customer onboarding workflows
  • Market research data collection
  • User experience research
  • Detailed feedback collection
  • Open-ended user interviews
APIsnew Agenttool(stepCountIsvalidateUIMessagesuseChatInferAgentUIMessagegenerateObject
Servicesopenai
Tagsaihuman-in-the-looptext-inputinteractive-questionsapproval-workflowsai-sdkbrand-contextstrategic-questioningtool-approvalstreamingopen-ended-questions
Tool Input Lifecycle Hooks preview

Explore tool input lifecycle hooks: onInputStart, onInputDelta, and onInputAvailable. See how to track tool input generation in real-time during streaming.

Problems Solved

  • Track tool input generation in real-time
  • Monitor tool input streaming with lifecycle hooks
  • Understand tool input lifecycle events
  • Debug tool input generation process

Use Cases

  • Learning tool input lifecycle hooks
  • Debugging tool input generation
  • Monitoring tool input streaming
  • Understanding AI SDK tool APIs
APIsstreamTextconvertToModelMessagestool(useChatonInputStartonInputDeltaonInputAvailable
Servicesopenai
Tagsaitoolslifecycle-hooksonInputStartonInputDeltaonInputAvailablestreamingai-sdktool-api
Preliminary Tool Results preview

Return preliminary tool results using async iterables. Stream status updates during tool execution before the final result is available.

Problems Solved

  • Stream preliminary tool results during execution
  • Provide status updates before final result
  • Use async iterables for progressive tool results
  • Display intermediate states during tool execution

Use Cases

  • Streaming tool execution status
  • Progressive tool result updates
  • Long-running tool operations
  • Understanding async generator tool patterns
APIsstreamTextconvertToModelMessagestool(useChatasync-generator
Servicesopenai
Tagsaitoolspreliminary-resultsasync-iterablesgenerator-functionsstreamingai-sdktool-api
Tool API Context preview

Pass arbitrary context from generateText/streamText to tool execution via experimental_context. Access context in tool execute functions for dynamic behavior.

Problems Solved

  • Pass arbitrary context to tool execution
  • Dynamic tool behavior based on context
  • Access context in tool execute functions
  • Customize tool behavior without modifying tool definition

Use Cases

  • Passing user preferences to tools
  • Dynamic API key management
  • Context-aware tool behavior
  • User-specific tool customization
APIsstreamTextconvertToModelMessagestool(useChatexperimental_context
Servicesopenai
Tagsaitoolsexperimental-contextcontextdynamic-behaviorai-sdktool-api
Tool Call Repair preview

Repair invalid tool calls using experimental_repairToolCall. Fix schema validation errors without requiring additional steps that pollute message history.

Problems Solved

  • Repair invalid tool calls automatically
  • Fix schema validation errors without additional steps
  • Handle tool call failures gracefully
  • Use structured outputs for repair

Use Cases

  • Handling invalid tool calls from smaller models
  • Repairing complex schema validation errors
  • Automatic tool call error recovery
  • Improving tool call success rate
APIsstreamTextconvertToModelMessagestool(useChatexperimental_repairToolCallgenerateObjectNoSuchToolError
Servicesopenai
Tagsaitoolstool-call-repairexperimental-repairToolCallschema-validationerror-handlingai-sdktool-api
Dynamic Tool preview

Create 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.

Problems Solved

  • Create tools with runtime-generated schemas
  • Adapt tool schemas based on user selection
  • Support dynamic model selection
  • Demonstrate dynamic tool creation patterns
  • Handle tools with unknown schemas at compile time

Use Cases

  • Unit conversion tools with dynamic schemas
  • MCP (Model Context Protocol) tools
  • User-defined functions at runtime
  • Tools loaded from external sources
  • Dynamic tool configuration based on user input
APIsstreamTextconvertToModelMessagesdynamicTooluseChatprepareSendMessagesRequest
Servicesopenaianthropicgoogle
Tagsaitoolsdynamic-toolruntime-toolsunit-converterschema-generationdynamic-schemaai-sdktool-apimodel-selection
Structured Agent Output: Output.choice preview

Demonstrate structured agent outputs using ToolLoopAgent with Output.choice. Constrain agent outputs to predefined choices for predictable, type-safe responses.

Problems Solved

  • Constrain agent outputs to predefined choices
  • Ensure type-safe agent responses
  • Create predictable agent outputs
  • Integrate structured outputs with tool-calling agents

Use Cases

  • Clothing recommendation systems with constrained choices
  • Form validation and structured data collection
  • API responses with guaranteed formats
  • Type-safe agent workflows
APIsToolLoopAgentOutput.choiceagent.generatetool
Servicesopenai
Tagsaiagentsstructured-outputstool-loop-agentoutput-choiceai-sdkagent-api
Structured Agent Output: Output.array preview

Demonstrate structured agent outputs using ToolLoopAgent with Output.array. Returns structured array output with element schema for predictable, type-safe responses.

Problems Solved

  • Generate structured array outputs with element schemas
  • Ensure type-safe agent responses
  • Create predictable agent outputs
  • Integrate structured outputs with tool-calling agents

Use Cases

  • Multi-location data aggregation with structured arrays
  • Form validation and structured data collection
  • API responses with guaranteed formats
  • Type-safe agent workflows
APIsToolLoopAgentOutput.arrayagent.generatetool
Servicesopenai
Tagsaiagentsstructured-outputstool-loop-agentoutput-arrayai-sdkagent-api
Sub-Agent Orchestrator preview

Custom Agent implementation demonstrating the Agent interface abstraction with an orchestrator that routes queries to specialized sub-agents (research, analysis, support). Shows options passing and structured outputs.

Problems Solved

  • Custom agent architecture implementation
  • Sub-agent orchestration pattern
  • Type-safe options passing to agents
  • Structured agent outputs
  • Agent routing and delegation

Use Cases

  • Multi-agent systems
  • Specialized agent routing
  • Custom agent architectures
  • Options-based agent configuration
  • Structured output generation
APIsToolLoopAgentcreateAgentUIStreamResponsetool(Output.objectstepCountIsgatewayInferAgentUIMessage
Servicesopenaiexa
Tagsaiagentsorchestratorai-sdkcustom-agentsub-agentsroutingoptionsstructured-output
Human in the Loop Plan Builder Agent preview

Uses ToolLoopAgent pattern to gather requirements and generate plans. Generates markdown plans with structured todo lists.

Problems Solved

  • Interactive plan building through conversation
  • Structured todo list generation with dependencies
  • Iterative plan refinement with user feedback
  • Human-in-the-loop approval workflows
  • Dynamic question generation with generateObject
  • Markdown plan rendering with sections

Use Cases

  • Project planning and task breakdown
  • Feature implementation planning
  • Migration and upgrade planning
  • API integration planning
  • Performance optimization planning
  • CI/CD pipeline setup planning
APIsToolLoopAgenttool(generateObjecttoModelOutputhasToolCallstepCountIsuseChatcreateUIMessageStreamstreamText
Servicesopenai
Tagsaihuman-in-the-loopplanningtodo-listmarkdowniterative-refinementapproval-workflowsai-sdktool-loop-agentgenerate-objectstreaming
Generate Speech (OpenAI) preview

Convert text to speech using OpenAI's API. Includes multiple voices, speed control, and real-time playback for voiceovers and accessibility.

APIsgenerateSpeech
Servicesopenai
Tagsaigenerate-speechopenaiaudiotts
Transcribe Audio (OpenAI) preview

Transcribe audio files using OpenAI's API. Includes real-time transcription and language detection.

APIstranscribe
Servicesopenai
Tagsaitranscribeopenaiaudiospeech-to-text
Generate Text preview

Generate text from prompts using AI. Simple interface with character counting and response rendering.

APIsgenerateTextconvertToModelMessages
Servicesopenaiperplexity
Tagsaiprompttext-generationai-sdkopenai
Stream Text preview

Stream text responses from AI prompts in real-time. Includes character counting and live response rendering with useCompletion.

APIsstreamTextuseCompletion
Servicesopenai
Tagsaiprompttext-generationstreamingai-sdkopenai
Streaming Structured Output preview

Stream structured output from AI prompts in real-time using streamText with Output.object(). Generate typed data with useObject and live rendering.

APIsstreamTextOutput.objectuseObject
Servicesopenai
Tagsaipromptobject-generationstreamingstructured-dataai-sdkopenaizod
OpenAI Structured Output preview

Generate structured output from AI prompts using OpenAI. Create typed data with generateText and Output.object().

APIsgenerateTextOutput.object
Servicesopenai
Tagsaipromptobject-generationstructured-dataai-sdkopenaizod
Claude Structured Output preview

Generate structured output from AI prompts using Anthropic Claude. Create typed data with generateText and Output.object().

APIsgenerateTextOutput.object
Servicesanthropic
Tagsaipromptobject-generationstructured-dataai-sdkclaudeanthropiczod
Gemini Structured Output preview

Generate structured output from AI prompts using Google Gemini. Create typed data with generateText and Output.object().

APIsgenerateTextOutput.object
Servicesgoogle
Tagsaipromptobject-generationstructured-dataai-sdkgooglegeminizod
Generate Image (OpenAI) preview

Generate images from text prompts using OpenAI's DALL-E 3. Create high-quality images with AI.

APIsexperimental_generateImage
Servicesopenai
Tagsaiimage-generationdalleai-sdkopenai
Generate Image (Fal.ai) preview

Generate images from text prompts using Fal.ai's Flux model. Fast and high-quality image generation.

APIsexperimental_generateImage
Servicesfal
Tagsaiimage-generationfluxfalai-sdk
Generate Speech (ElevenLabs) preview

Convert text to speech using ElevenLabs API. Includes multiple voices and high-quality audio generation.

APIsexperimental_generateSpeech
Serviceselevenlabs
Tagsaigenerate-speechelevenlabsaudiottsai-sdk
Transcribe Audio (ElevenLabs) preview

Transcribe audio files using ElevenLabs API. Includes real-time transcription and language detection.

APIsexperimental_transcribe
Serviceselevenlabs
Tagsaitranscribeelevenlabsaudiospeech-to-textai-sdk
Search - Exa AI (robust) preview

Search the web using Exa's semantic API and real-time crawling. Includes URL search, content extraction, Wikipedia, Reddit, and news search tools.

APIsstreamTextconvertToCoreMessagestool(useChat
Servicesopenaiexa
Tagsaisearchexaweb-searchsemantic-searchresearchtoolsai-sdk
Search - Firecrawl (robust) preview

Search the web using Firecrawl's API and real-time crawling. Includes URL search, content extraction, Wikipedia, Reddit, and news search tools.

APIsstreamTextconvertToCoreMessagestool(useChat
Servicesopenaifirecrawl
Tagsaisearchfirecrawlweb-searchsemantic-searchresearchtoolsai-sdk
Scrape - Cheerio (lightweight) preview

Scrape websites using Cheerio's fast HTML parser. Includes URL scraping, website crawling, and content extraction without external API costs.

APIsstreamTextconvertToCoreMessagestool(useChat
Servicesopenai
Tagsaiscrapecheerioweb-scrapinghtml-parsingresearchtoolsai-sdklightweightno-api-cost
Scrape - Jina AI (advanced) preview

Scrape websites using Jina AI's reader service with JavaScript rendering. Includes URL scraping, website crawling, and content extraction with AI-powered parsing.

APIsstreamTextconvertToCoreMessagestool(useChat
Servicesopenaijina
Tagsaiscrapejinaweb-scrapingjavascript-renderingresearchtoolsai-sdkadvancedreader-service
Scrape - Markdown.new (free) preview

Scrape websites using Cloudflare's markdown.new service. Extract clean markdown content from any URL. No API key required.

APIsstreamTextconvertToCoreMessagestool(useChat
Servicesopenaimarkdown.new
Tagsaiscrapemarkdown-newweb-scrapingcloudflareno-api-keytoolsai-sdk

Browse by Category

End of AI SDK v6