v0-sdk
TypeScript SDK for the v0 Platform API
The core TypeScript SDK for interacting with the v0 Platform API. Provides type-safe methods for creating chats, managing projects, handling deployments, and more.
Installation
npm install v0-sdk
# or
pnpm add v0-sdk
# or
yarn add v0-sdkQuick Start
import { V0 } from 'v0-sdk'
const v0 = new V0({
apiKey: process.env.V0_API_KEY,
})
// Create a new chat
const chat = await v0.chats.create({
message: 'Create a todo app with React',
})
console.log(chat.id)Features
- Type-safe API: Full TypeScript support with comprehensive type definitions
- Complete Coverage: Access all v0 Platform API endpoints
- Modern Architecture: Built with modern JavaScript/TypeScript patterns
- Error Handling: Comprehensive error handling and validation
- Streaming Support: Real-time streaming for chat responses
Core APIs
Chats
// Create a chat
const chat = await v0.chats.create({
message: 'Build a landing page',
})
// Send a message
const response = await v0.chats.sendMessage(chat.id, {
message: 'Add a contact form',
})
// Get chat history
const chatData = await v0.chats.getById(chat.id)Projects
// Create a project
const project = await v0.projects.create({
name: 'My App',
})
// Get project details
const projectData = await v0.projects.getById(project.id)
// List all projects
const projects = await v0.projects.find()Deployments
// Create a deployment
const deployment = await v0.deployments.create({
projectId: project.id,
chatId: chat.id,
versionId: chat.latestVersion.id,
})
// Get deployment status
const deploymentData = await v0.deployments.getById(deployment.id)
// Get deployment logs
const logs = await v0.deployments.findLogs(deployment.id)User & Account
// Get user information
const user = await v0.user.get()
// Get billing information
const billing = await v0.user.getBilling()
// Get current plan
const plan = await v0.user.getPlan()Configuration
Environment Variables
V0_API_KEY=your_api_key_here
V0_API_URL=https://api.v0.dev/v1 # Optional, defaults to productionClient Options
const v0 = new V0({
apiKey: 'your-api-key',
baseURL: 'https://api.v0.dev/v1', // Optional
timeout: 30000, // Optional, in milliseconds
maxRetries: 3, // Optional
})Error Handling
import { V0Error } from 'v0-sdk'
try {
const chat = await v0.chats.create({
message: 'Create an app',
})
} catch (error) {
if (error instanceof V0Error) {
console.error('API Error:', error.message)
console.error('Status:', error.status)
console.error('Code:', error.code)
} else {
console.error('Unexpected error:', error)
}
}Requirements
- Node.js 22+
- TypeScript 5.0+ (for TypeScript projects)