This example demonstrates how to use @v0-sdk/ai-tools with the AI SDK to interact with the v0 platform programmatically.
-
Install dependencies:
pnpm install
-
Set up environment variables: Create a
.envfile in this directory:V0_API_KEY=your_v0_api_key_here AI_GATEWAY_API_KEY=your_ai_gateway_api_key_here
-
Get your API keys:
- v0 API Key: Get from v0.dev account settings
- AI Gateway API Key: Get from vercel.com AI Gateway settings
pnpm devShows the basic structure and available tools without AI SDK complexity.
# Complete workflow examples
pnpm dev:full
# Chat-focused example
pnpm dev:chat
# Project management example
pnpm dev:project
# Advanced agent patterns example
pnpm dev:agentNote: The full AI integration examples require compatible versions of AI SDK and may have type compatibility issues. Start with the simple example first.
import { v0Tools } from '@v0-sdk/ai-tools'
const result = await generateText({
model: 'openai/gpt-4o-mini',
prompt: 'Create a new React component',
tools: v0Tools({ apiKey: process.env.V0_API_KEY }),
})import { v0ToolsByCategory } from '@v0-sdk/ai-tools'
const tools = v0ToolsByCategory({ apiKey: process.env.V0_API_KEY })
const result = await generateText({
model: 'openai/gpt-4o-mini',
prompt: 'Create a new project and chat',
tools: {
...tools.project, // Only project tools
...tools.chat, // Only chat tools
},
})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
The dev:agent example demonstrates advanced AI agent patterns:
- Autonomous agents that can plan and execute complex workflows
- Uses
stepCountIs()to control execution length - Structured answers with answer tools
- Step-by-step workflows where each step builds on the previous
- Quality checks and iterative improvement
- Requirements analysis → Project creation → Validation
- Intelligent request classification and routing
- Dynamic model selection based on complexity
- Context-aware tool selection
- Independent tasks executed simultaneously
- Efficient resource utilization
- Result synthesis from multiple analyses
- Feedback loops for continuous improvement
- Quality assessment and iterative refinement
- Self-improving workflows
- 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
- "Invalid API key": Check your
.envfile 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