AI Tools Example
Using v0-sdk with AI SDK for programmatic interaction
Learn how to build AI agents that can autonomously interact with the v0 platform using @v0-sdk/ai-tools
and the AI SDK for complex workflows and automation.
Setup
-
Install dependencies:
-
Set up environment variables: Create a
.env
file in this directory: -
Get your API keys:
- v0 API Key: Get from v0.dev account settings
- AI Gateway API Key: Get from vercel.com AI Gateway settings
Examples
Simple Example (Recommended Start)
Shows the basic structure and available tools without AI SDK complexity.
Full AI Integration Examples
Note: The full AI integration examples require compatible versions of AI SDK and may have type compatibility issues. Start with the simple example first.
Key Concepts
1. All Tools (High Context)
⚠️ Note: This includes all ~20+ tools which adds significant context to your AI calls.
2. Selective Tools (Recommended)
3. Available Tool Categories
tools.chat
- Create, manage, and interact with v0 chatstools.project
- Create and manage v0 projectstools.deployment
- Handle deployments and logstools.user
- Get user information and billing detailstools.hook
- Manage webhooks for events
Agent Patterns
The dev:agent
example demonstrates advanced AI agent patterns:
1. Multi-Step Agent with stopWhen
- Autonomous agents that can plan and execute complex workflows
- Uses
stepCountIs()
to control execution length - Structured answers with answer tools
2. Sequential Processing (Chains)
- Step-by-step workflows where each step builds on the previous
- Quality checks and iterative improvement
- Requirements analysis → Project creation → Validation
3. Routing Agent
- Intelligent request classification and routing
- Dynamic model selection based on complexity
- Context-aware tool selection
4. Parallel Processing
- Independent tasks executed simultaneously
- Efficient resource utilization
- Result synthesis from multiple analyses
5. Evaluator-Optimizer
- Feedback loops for continuous improvement
- Quality assessment and iterative refinement
- Self-improving workflows
Tips
- Start with selective tools - Only include the categories you need to reduce context size
- Use
stopWhen
- Control agent execution with conditions likestepCountIs(n)
- Handle errors - Wrap AI calls in try-catch blocks
- Monitor usage - Check your API usage on both v0 and AI Gateway platforms
Troubleshooting
- "Invalid API key": Check your
.env
file and API key validity - "Tool not found": Ensure you're using the correct tool category
- Rate limits: Both v0 and AI Gateway have rate limits - add delays if needed
Source Code
View the complete source code on GitHub: v0-sdk/examples/ai-tools-example