Quickstart
Get started with the v0 Platform API in minutes
v0 SDK
The v0 SDK is a TypeScript library that makes it simple to interact with the v0 Platform API.
Installation
pnpm add v0-sdkAuthentication
Get your API key from your v0 account settings and set it as an environment variable:
Add your API key to .env:
V0_API_KEY=your_api_key_hereThe SDK automatically uses the V0_API_KEY environment variable:
import { v0 } from 'v0-sdk'
// No initialization needed - uses V0_API_KEY automaticallyUse Case 1: Get a Chat URL for Iframe Embedding
Create a chat and embed it directly in your application:
// Create a new chat
const chat = await v0.chats.create({
message: 'Create a responsive navbar with Tailwind CSS'
})
// Use the Demo URL in an iframe
<iframe
src={chat.demo}
width="100%"
height="600">
</iframe>Use Case 2: Get Generated Files
Create a chat and access the generated code files:
// Create a chat
const chat = await v0.chats.create({
message: 'Build a todo app with React and TypeScript',
})
// Access the generated files
chat.files?.forEach((file) => {
console.log(`File: ${file.name}`)
console.log(`Content: ${file.content}`)
})Continue the Conversation
Add follow-up messages to refine the output:
// Add a follow-up message
const response = await v0.chats.sendMessage({
chatId: chat.id,
message: 'Add dark mode support',
})That's it! You now have everything you need to integrate v0's AI-powered code generation into your application.