### Example: Create and Run a Classic v0 App Source: https://v0.app/docs/api/platform/packages/create-v0-sdk-app Steps to create a 'classic-v0' project, install dependencies, and start the development server. ```bash npx create-v0-sdk-app@latest my-classic-app --template classic-v0 cd my-classic-app pnpm install pnpm dev ``` -------------------------------- ### Example: Create and Run a v0 Clone App Source: https://v0.app/docs/api/platform/packages/create-v0-sdk-app Steps to create a 'v0-clone' project, set up environment variables, install dependencies, migrate the database, and start the development server. ```bash npx create-v0-sdk-app@latest my-v0-clone --template v0-clone cd my-v0-clone ``` ```bash cp .env.example .env # Edit .env with your API keys ``` ```bash pnpm install pnpm db:migrate # For v0-clone template pnpm dev ``` -------------------------------- ### Install Dependencies Source: https://v0.app/docs/api/platform/examples/classic-v0 Navigate to the example directory and install project dependencies using pnpm. ```bash cd examples/classic-v0 pnpm install ``` -------------------------------- ### Run Development Server Source: https://v0.app/docs/api/platform/examples/classic-v0 Start the development server for the classic v0 example application. ```bash pnpm dev ``` -------------------------------- ### Post-Creation Steps for New App Source: https://v0.app/docs/api/platform/packages/create-v0-sdk-app Essential steps after creating an app, including setting up environment variables, installing dependencies, database migration (if applicable), and starting the development server. ```bash cp .env.example .env # Add your V0_API_KEY ``` ```bash pnpm install ``` ```bash pnpm db:migrate ``` ```bash pnpm dev ``` -------------------------------- ### Install and Run create-v0-sdk-app Source: https://v0.app/docs/api/platform/packages/create-v0-sdk-app Use npx to run the latest version of the create-v0-sdk-app without global installation, or install it globally for repeated use. ```bash npx create-v0-sdk-app@latest my-app ``` ```bash npm install -g create-v0-sdk-app create-v0-sdk-app my-app ``` -------------------------------- ### Install v0 SDK Source: https://v0.app/docs/api/platform/quickstart Install the v0 SDK using pnpm. This is the first step to interact with the v0 Platform API. ```bash pnpm add v0-sdk ``` -------------------------------- ### Install v0 SDK Source: https://v0.app/docs/api/platform/packages/v0-sdk Install the v0 SDK using npm, pnpm, or yarn. ```bash npm install v0-sdk # or pnpm add v0-sdk # or yarn add v0-sdk ``` -------------------------------- ### Install @v0-sdk/react and Dependencies Source: https://v0.app/docs/api/platform/guides/displaying-chat-messages Install the necessary packages for using the @v0-sdk/react library, including optional support for math rendering with katex. ```bash npm install @v0-sdk/react v0-sdk # For math rendering support npm install katex ``` -------------------------------- ### Install @v0-sdk/react Source: https://v0.app/docs/api/platform/packages/react Install the @v0-sdk/react package using npm, pnpm, or yarn. ```bash npm install @v0-sdk/react # or pnpm add @v0-sdk/react # or yarn add @v0-sdk/react ``` -------------------------------- ### Database Integration Example Source: https://v0.app/docs/MCP This example demonstrates how v0 uses the 'neon_query' tool to inspect the schema of a 'users' table after a Neon database integration is connected. ```text User: "Show me the schema for my users table" v0: [Uses neon_query tool to inspect schema] "Your users table has these columns: - id (uuid, primary key) - email (varchar) - created_at (timestamp) - updated_at (timestamp)" ``` -------------------------------- ### Install v0 SDK Source: https://v0.app/docs/api/platform/overview Install the v0 SDK using npm or pnpm. This is the first step to interacting with the v0 Platform API. ```bash npm install v0-sdk # or pnpm add v0-sdk ``` -------------------------------- ### Install @v0-sdk/ai-tools Source: https://v0.app/docs/api/platform/packages/ai-tools Install the @v0-sdk/ai-tools package and the ai SDK using npm, pnpm, or yarn. ```bash npm install @v0-sdk/ai-tools ai # or pnpm add @v0-sdk/ai-tools ai # or yarn add @v0-sdk/ai-tools ai ``` -------------------------------- ### List Projects API Endpoint Source: https://v0.app/docs/api/platform/overview Example of a GET request to list all projects. ```http GET https://api.v0.dev/v1/projects # List projects ``` -------------------------------- ### Quick Start with v0 SDK Source: https://v0.app/docs/api/platform/packages/v0-sdk Initialize the SDK and create a new chat. ```typescript 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) ``` -------------------------------- ### Run Full AI Integration Examples Source: https://v0.app/docs/api/platform/examples/ai-tools Execute different examples for full AI integration, including complete workflows, chat-focused scenarios, project management, and advanced agent patterns. ```bash # Complete workflow examples pnpm dev:full # Chat-focused example pnpm dev:chat # Project management example pnpm dev:project # Advanced agent patterns example pnpm dev:agent ``` -------------------------------- ### Install Dependencies Source: https://v0.app/docs/api/platform/examples/ai-tools Install necessary project dependencies using pnpm. ```bash pnpm install ``` -------------------------------- ### Install AI Tools SDK Source: https://v0.app/docs/api/platform/adapters/ai-tools Install the necessary packages for AI tools integration using npm or pnpm. ```bash npm install @v0-sdk/ai-tools ai # or pnpm add @v0-sdk/ai-tools ai ``` ```bash # LangChain integration npm install @v0-sdk/langchain-tools langchain # OpenAI Functions npm install @v0-sdk/openai-functions openai ``` -------------------------------- ### Start a Chat Session Source: https://v0.app/docs/api/platform/overview Initiate a chat session either by initializing with existing code or starting from scratch with AI generation. Initializing with existing files is recommended for speed and efficiency. ```typescript // Start chat with existing code (recommended) const chat = await v0.chats.init({ files: existingFiles, initialContext: 'Help me optimize this React component', }) // Start chat from scratch with AI generation const chat = await v0.chats.create({ initialMessage: 'Create a todo app with React and TypeScript', }) ``` -------------------------------- ### Create Project API Endpoint Source: https://v0.app/docs/api/platform/overview Example of a POST request to create a new project. ```http POST https://api.v0.dev/v1/projects # Create project ``` -------------------------------- ### Get Messages API Endpoint Source: https://v0.app/docs/api/platform/overview Example of a GET request to retrieve messages from a chat. ```http GET https://api.v0.dev/v1/chats/:id/messages # Get messages ``` -------------------------------- ### Get Project API Endpoint Source: https://v0.app/docs/api/platform/overview Example of a GET request to retrieve a specific project by its ID. ```http GET https://api.v0.dev/v1/projects/:id # Get project ``` -------------------------------- ### Deployment Tools Example Source: https://v0.app/docs/api/platform/packages/ai-tools Employ the 'deployment' tools to initiate a project deployment and monitor its status. Ensure 'tools.deployment' is correctly imported and available. ```typescript const result = await generateText({ model: openai('gpt-4o-mini'), prompt: 'Deploy the project and check its status', tools: tools.deployment, }) ``` -------------------------------- ### Create and Initialize a Project Source: https://v0.app/docs/api/platform/overview Demonstrates creating a new project and initializing a chat with existing files. Use `v0.chats.init` for faster initialization when you have existing code. ```typescript // Create a new project const project = await v0.projects.create({ name: 'My React App', }) // Most common: Initialize from existing files const chat = await v0.chats.init({ type: 'files', files: [ { name: 'src/App.tsx', content: appCode }, { name: 'package.json', content: packageJson }, ], projectId: project.id, }) ``` -------------------------------- ### Get Environment Variable using TypeScript Source: https://v0.app/docs/api/platform/reference/projects/get-env-var Use this snippet to retrieve an environment variable by its project and ID. Set 'decrypted' to 'true' to get the unencrypted value. Ensure you have the v0-sdk installed. ```TypeScript import { v0 } from 'v0-sdk' const result = await v0.projects.getEnvVar({ projectId: 'project_abc123', environmentVariableId: 'env_def456', decrypted: 'true', }) console.log(result) ``` ```cURL curl -X GET https://api.v0.dev/v1/projects/project_abc123/env-vars/env_def456?decrypted=true \ -H "Authorization: Bearer $V0_API_KEY" \ -H "Content-Type: application/json" ``` -------------------------------- ### Send Message using TypeScript and cURL Source: https://v0.app/docs/api/platform/reference/chats/send-message Use this snippet to send a message to a chat. Ensure you have the v0 SDK installed for the TypeScript example. The cURL example requires your V0_API_KEY environment variable to be set. ```TypeScript import { v0 } from 'v0-sdk' const result = await v0.chats.sendMessage({ chatId: '123', message: 'Add dark mode', }) console.log(result) ``` ```cURL curl -X POST https://api.v0.dev/v1/chats/123/messages \ -H "Authorization: Bearer $V0_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "message": "Add dark mode" }' ``` -------------------------------- ### Create AI Tools Example Template Source: https://v0.app/docs/api/platform/packages/create-v0-sdk-app Scaffold a project using the 'ai-tools-example' template, demonstrating AI SDK integration and autonomous agent patterns. ```bash npx create-v0-sdk-app@latest my-app --template ai-tools-example ``` -------------------------------- ### Get User Activity Report (TypeScript) Source: https://v0.app/docs/api/platform/reference/reports/get-user-activity Use this snippet to fetch user activity data programmatically. Ensure you have the v0-sdk installed and are authenticated. ```TypeScript import { v0 } from 'v0-sdk' const result = await v0.reports.getUserActivity() console.log(result) ``` -------------------------------- ### Get Usage Report with TypeScript Source: https://v0.app/docs/api/platform/reference/reports/get-usage Use this snippet to retrieve usage data using the v0 SDK. Ensure you have the SDK installed and authenticated. ```TypeScript import { v0 } from 'v0-sdk' const result = await v0.reports.getUsage() console.log(result) ``` -------------------------------- ### create-v0-sdk-app Command Structure Source: https://v0.app/docs/api/platform/packages/create-v0-sdk-app Basic syntax for using the create-v0-sdk-app command, including optional project name and options. ```bash create-v0-sdk-app [project-name] [options] ``` -------------------------------- ### Get Chat Message using TypeScript Source: https://v0.app/docs/api/platform/reference/chats/get-message Use this snippet to retrieve a specific message from a chat. Ensure you have the v0 SDK installed and configured. ```TypeScript import { v0 } from 'v0-sdk' const result = await v0.chats.getMessage() console.log(result) ``` -------------------------------- ### Get Project by Chat ID using TypeScript Source: https://v0.app/docs/api/platform/reference/projects/get-by-chat-id Use this snippet to retrieve a project by its chat ID in TypeScript. Ensure you have the v0 SDK installed and configured. ```TypeScript import { v0 } from 'v0-sdk' const result = await v0.projects.getByChatId({ chatId: '123', }) console.log(result) ``` -------------------------------- ### Find MCP Servers with cURL Source: https://v0.app/docs/api/platform/reference/mcp-servers/find This example shows how to make a GET request to the /mcp-servers endpoint using cURL. Ensure you include your API key in the Authorization header. ```cURL curl -X GET https://api.v0.dev/v1/mcp-servers \ -H "Authorization: Bearer $V0_API_KEY" \ -H "Content-Type: application/json" ``` -------------------------------- ### Get User Plan in TypeScript Source: https://v0.app/docs/api/platform/reference/user/get-plan Use this snippet to fetch the current user's plan details using the v0 SDK. Ensure the SDK is properly installed and authenticated. ```TypeScript import { v0 } from 'v0-sdk' const result = await v0.user.getPlan() console.log(result) ``` -------------------------------- ### Create Project with cURL Source: https://v0.app/docs/api/platform/reference/projects/create This example demonstrates how to create a project using a cURL command. Replace $V0_API_KEY with your actual API key and adjust the JSON payload as needed. ```cURL curl -X POST https://api.v0.dev/v1/projects \ -H "Authorization: Bearer $V0_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "name": "My Project" }' ``` -------------------------------- ### Mark or Unmark Chat as Favorite Source: https://v0.app/docs/api/platform/reference/chats/favorite Use this snippet to mark a chat as a favorite by setting `isFavorite` to `true`, or remove it from favorites by setting it to `false`. Ensure you have the `v0-sdk` installed for the TypeScript example. ```TypeScript import { v0 } from 'v0-sdk' const result = await v0.chats.favorite({ chatId: '123', isFavorite: true, }) console.log(result) ``` ```cURL curl -X POST https://api.v0.dev/v1/chats/123/favorite \ -H "Authorization: Bearer $V0_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "isFavorite": true }' ``` -------------------------------- ### create-v0-sdk-app Options Source: https://v0.app/docs/api/platform/packages/create-v0-sdk-app Available command-line options for create-v0-sdk-app, such as specifying a template, package manager, or viewing help/version. ```bash --template - Specify template (v0-clone, classic-v0, ai-tools-example) ``` ```bash --package-manager - Choose package manager (npm, pnpm, yarn) ``` ```bash --help - Show help information ``` ```bash --version - Show version number ``` -------------------------------- ### Project Tools Example Source: https://v0.app/docs/api/platform/packages/ai-tools Use the 'project' tools to create a new project with a specified name. Ensure 'tools.project' is correctly imported and available. ```typescript const result = await generateText({ model: openai('gpt-4o-mini'), prompt: 'Create a new project called "My Portfolio"', tools: tools.project, }) ``` -------------------------------- ### Set Up Environment Variables Source: https://v0.app/docs/api/platform/examples/ai-tools Configure environment variables for v0 API key and AI Gateway API key. ```bash V0_API_KEY=your_v0_api_key_here AI_GATEWAY_API_KEY=your_ai_gateway_api_key_here ``` -------------------------------- ### Create a Project Source: https://v0.app/docs/api/platform/packages/v0-sdk Create a new project using the SDK. ```typescript // Create a project const project = await v0.projects.create({ name: 'My App', }) ``` -------------------------------- ### Make Your First v0 API Call Source: https://v0.app/docs/api/platform/overview Import the v0 SDK and make a call to list your projects. Ensure you have generated an API key from the v0.dev settings. ```typescript import { v0 } from 'v0-sdk' // List your projects const projects = await v0.projects.list() console.log('Your projects:', projects.data) ``` -------------------------------- ### Create Project and Initialize Chat Source: https://v0.app/docs/api/platform/guides/start-from-existing-code First, create a project with environment variables, then initialize a chat using the created project's ID. This allows setting up project-specific configurations before starting a chat. ```typescript // Create a project first const project = await v0.projects.create({ name: 'My React App', description: 'Imported React application', environmentVariables: [ { key: 'NODE_ENV', value: 'development' }, { key: 'API_URL', value: 'http://localhost:3001' }, ], }) // Then initialize chat with the project const chat = await v0.chats.init({ type: 'repo', repo: { url: 'https://github.com/username/react-app', }, projectId: project.id, name: 'Development Chat', }) ``` -------------------------------- ### Environment Variables Setup Source: https://v0.app/docs/api/platform/examples/v0-clone Configure necessary environment variables for authentication, database connection, and the v0 API key. Ensure AUTH_SECRET is a randomly generated string for production. ```bash # Auth Secret - Generate a random string for production # Generate with: openssl rand -base64 32 # Or visit: https://generate-secret.vercel.app/32 AUTH_SECRET=your-auth-secret-here # Database URL - PostgreSQL connection string POSTGRES_URL=postgresql://user:password@localhost:5432/v0_clone # For Vercel Postgres, use the connection string from your dashboard # Get your API key from https://v0.dev/chat/settings/keys V0_API_KEY=your_v0_api_key_here # Optional: Use a custom API URL # V0_API_URL=http://localhost:3001/v1 ``` -------------------------------- ### Get User Activity Report (cURL) Source: https://v0.app/docs/api/platform/reference/reports/get-user-activity This cURL command demonstrates how to make a GET request to the user activity endpoint. Replace `$V0_API_KEY` with your actual API key. ```cURL curl -X GET https://api.v0.dev/v1/reports/user-activity \ -H "Authorization: Bearer $V0_API_KEY" \ -H "Content-Type: application/json" ``` -------------------------------- ### Invoke Pre-installed Agent Source: https://v0.app/docs/pre-installed-agents Open the terminal in your v0 project and run the agent's CLI command to start using it. The agent launches within the sandbox and can interact with your project files. ```bash claude ``` -------------------------------- ### Use All Available Tools with v0Tools Source: https://v0.app/docs/api/platform/packages/ai-tools Initialize v0Tools with your API key to provide all available tools for maximum capability. This approach adds significant context to AI calls. ```typescript import { v0Tools } from '@v0-sdk/ai-tools' const tools = v0Tools({ apiKey: process.env.V0_API_KEY, }) const result = await generateText({ model: openai('gpt-4o-mini'), prompt: 'Build a complete web app with deployment', tools, }) ``` -------------------------------- ### Select Tool Categories Source: https://v0.app/docs/api/platform/adapters/ai-tools Instantiate v0 tools by specifying categories for optimized performance. This example combines project and chat tools. ```typescript import { v0ToolsByCategory } from '@v0-sdk/ai-tools' const tools = v0ToolsByCategory({ apiKey: process.env.V0_API_KEY, }) // Use specific categories const projectAndChatTools = { ...tools.project, ...tools.chat, } ``` -------------------------------- ### Update Chat with TypeScript and cURL Source: https://v0.app/docs/api/platform/reference/chats/update Use this snippet to update a chat's name, privacy, and metadata. The TypeScript example utilizes the v0 SDK, while the cURL example shows a direct API call. ```TypeScript import { v0 } from 'v0-sdk' const result = await v0.chats.update({ chatId: '123', name: 'My Renamed Chat', privacy: 'public', metadata: { userId: 'user_123', sessionId: 'session_456' } }) console.log(result) ``` ```cURL curl -X PATCH https://api.v0.dev/v1/chats/123 \ -H "Authorization: Bearer $V0_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "name": "My Renamed Chat", "privacy": "public", "metadata": { "userId": "user_123", "sessionId": "session_456" } }' ``` -------------------------------- ### Assign Project to Chat Source: https://v0.app/docs/api/platform/reference/projects/assign Use this snippet to link a project to a chat. Ensure you have the project ID and chat ID ready. The TypeScript example uses the v0 SDK, while the cURL example shows a direct API call. ```TypeScript import { v0 } from 'v0-sdk' const result = await v0.projects.assign({ projectId: '123', chatId: '123', }) console.log(result) ``` ```cURL curl -X POST https://api.v0.dev/v1/projects/123/assign \ -H "Authorization: Bearer $V0_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "chatId": "123" }' ``` -------------------------------- ### Interactive Mode for create-v0-sdk-app Source: https://v0.app/docs/api/platform/packages/create-v0-sdk-app Run the command without arguments to enter interactive mode, where you will be prompted for project name, template, and package manager. ```bash npx create-v0-sdk-app@latest ``` -------------------------------- ### Get Chat by ID Source: https://v0.app/docs/api/platform/reference/chats/get-by-id Fetches a chat by its unique identifier. ```APIDOC ## GET /v0/app/chats/{id} ### Description Retrieves the details of a specific chat using its unique identifier. ### Method GET ### Endpoint /v0/app/chats/{id} ### Parameters #### Path Parameters - **id** (string) - Required - A unique identifier for the chat. ### Response #### Success Response (200) - **id** (string) - A unique identifier for the chat. - **object** ('chat') - Fixed value identifying this object as a chat. - **shareable** (boolean) - Deprecated: Use the `privacy` field instead. A chat is shareable when privacy is public or unlisted. - **privacy** ('public' | 'private' | 'team' | 'team-edit' | 'unlisted') - Defines the visibility of the chat—private, team-only, or public. - **name** (string) - An optional name assigned to the chat by the user. - **title** (string) - Deprecated title field preserved for backward compatibility. - **createdAt** (string) - The ISO timestamp representing when the chat was created. - **updatedAt** (string) - The ISO timestamp of the last update to the chat. - **favorite** (boolean) - Indicates whether the chat is marked as a favorite. - **authorId** (string) - The ID of the user who created the chat. - **projectId** (string) - Optional ID of the v0 project associated with this chat. - **vercelProjectId** (string) - Optional ID of the linked Vercel project, if connected. - **webUrl** (string) - Web URL to view this chat in the browser. - **apiUrl** (string) - API URL to access this chat via the API. - **latestVersion** (object) - Full details of the most recent generated version, if available. - **id** (string) - A unique identifier for the version. - **object** ('version') - Fixed value identifying this object as a version. - **status** ('pending' | 'completed' | 'failed') - The current status of the version generation process. - **demoUrl** (string) - Optional URL for previewing the generated output. - **screenshotUrl** (string) - An authenticated URL to retrieve a screenshot of this version. Fetching this URL requires the same Authorization: Bearer header as all other API calls — it cannot be used directly as an src. To display it in a browser, proxy the request server-side and forward the Authorization header. Append ?ignoreCache=1 to bypass the one-week screenshot cache. - **createdAt** (string) - The date and time when the version was created, in ISO 8601 format. - **updatedAt** (string) - The date and time when the version was last updated, in ISO 8601 format. - **files** (object[]) - A list of files that were generated or included in this version. - **item** (object) - Detailed representation of a file, including its content and lock status. #### Response Example { "id": "chat_abc123", "object": "chat", "shareable": true, "privacy": "public", "name": "My Awesome Chat", "createdAt": "2023-10-27T10:00:00Z", "updatedAt": "2023-10-27T10:05:00Z", "favorite": false, "authorId": "user_xyz789", "projectId": "proj_12345", "vercelProjectId": "null", "webUrl": "https://example.com/chats/chat_abc123", "apiUrl": "https://api.example.com/v0/app/chats/chat_abc123", "latestVersion": { "id": "version_def456", "object": "version", "status": "completed", "demoUrl": "https://demo.example.com/version_def456", "screenshotUrl": "https://api.example.com/v0/app/versions/version_def456/screenshot?ignoreCache=1", "createdAt": "2023-10-27T10:05:00Z", "updatedAt": "2023-10-27T10:05:00Z", "files": [ { "id": "file_ghi789", "object": "file", "name": "index.html", "source": "generated", "size": 1024, "type": "text/html", "sha1": "a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0", "status": "complete", "createdAt": "2023-10-27T10:05:00Z" } ] } } ``` -------------------------------- ### Get User Information Source: https://v0.app/docs/api/platform/packages/v0-sdk Retrieve information about the current user. ```typescript // Get user information const user = await v0.user.get() ``` -------------------------------- ### Create Project Source: https://v0.app/docs/api/platform/reference/projects/create Creates a new v0 project with an optional description, icon, environment variables, and instructions. Projects help organize chats and manage context. ```APIDOC ## POST /projects ### Description Creates a new v0 project with an optional description, icon, environment variables, and instructions. Projects help organize chats and manage context. ### Method POST ### Endpoint /projects ### Request Body - **name** (string) - Required - The name of the project. - **description** (string) - Optional - A brief summary of the project’s purpose. - **icon** (string) - Optional - An icon identifier to visually represent the project. - **environmentVariables** (object[]) - Optional - A list of key-value pairs used to define runtime variables for the project. - **item** (object) - Required - **key** (string) - Required - **value** (string) - Required - **instructions** (string) - Optional - Guidance or goals that provide context for the model when working within the project. - **vercelProjectId** (string) - Optional - The ID of an existing Vercel project to link to. If not provided, a new Vercel project will be created. - **privacy** ('private' | 'team') - Optional - The privacy setting for the project. For user accounts, this is always "private". For team/enterprise accounts, this can be either "private" or "team". ### Request Example ```json { "name": "My Project" } ``` ### Response #### Success Response (200) - **id** (string) - The unique identifier for the created project. - **name** (string) - The name of the project. - **description** (string) - The project's description. - **icon** (string) - The project's icon identifier. - **createdAt** (string) - The timestamp when the project was created. - **updatedAt** (string) - The timestamp when the project was last updated. - **environmentVariables** (object[]) - The project's environment variables. - **instructions** (string) - The project's instructions. - **vercelProjectId** (string) - The linked Vercel project ID. - **privacy** ('private' | 'team') - The project's privacy setting. #### Response Example ```json { "id": "proj_abc123", "name": "My Project", "description": "A sample project.", "icon": "default", "createdAt": "2023-01-01T12:00:00Z", "updatedAt": "2023-01-01T12:00:00Z", "environmentVariables": [ { "key": "API_KEY", "value": "secret" } ], "instructions": "Follow these steps.", "vercelProjectId": "vercel_xyz789", "privacy": "private" } ``` ``` -------------------------------- ### Get Chat by ID Source: https://v0.app/docs/api/platform/reference/chats/get-by-id Fetches a chat conversation by its unique ID. ```APIDOC ## GET /chats/{chat_id} ### Description Retrieves a specific chat conversation by its unique identifier. ### Method GET ### Endpoint /chats/{chat_id} ### Parameters #### Path Parameters - **chat_id** (string) - Required - The unique identifier of the chat to retrieve. ### Response #### Success Response (200) - **id** (string) - The unique identifier of the chat. - **url** (string) - The canonical URL to access this chat. (Deprecated) - **messages** (object[]) - An array of message objects exchanged in the chat. - **id** (string) - A unique identifier for the message. - **object** ('message') - Fixed value identifying this object as a message. - **content** (string) - The main text content of the message. - **experimental_content** (any[] | any[][]) - The parsed content of the message as an array structure containing AST nodes. (Experimental) - **createdAt** (string) - The ISO timestamp representing when the message was created. - **updatedAt** (string) - The ISO timestamp representing when the message was last updated. - **type** (string) - Indicates the format or category of the message, such as plain text or code. - **role** ('user' | 'assistant') - Specifies whether the message was sent by the user or the assistant. - **finishReason** (string) - The reason why the message generation finished. - **apiUrl** (string) - API URL to access this message via the API. - **authorId** (string | null) - The ID of the user who sent the message. - **parentId** (string | null) - The ID of the parent message, if this is a reply. #### Response Example { "id": "chat_abc123", "url": "/chat/abc123", "messages": [ { "id": "msg_xyz789", "object": "message", "content": "Hello there!", "createdAt": "2023-10-27T10:00:00Z", "updatedAt": "2023-10-27T10:00:00Z", "type": "message", "role": "user", "finishReason": "stop", "apiUrl": "/v0/chats/chat_abc123/messages/msg_xyz789", "authorId": "user_123", "parentId": null } ] } ``` -------------------------------- ### Direct API Usage: Create Project and Initialize Chat Source: https://v0.app/docs/api/platform/overview Use the core SDK for full control. Initialize a chat with files and associate it with a project. ```typescript import { v0 } from 'v0-sdk' // Or with custom configuration: // import { createClient } from 'v0-sdk' // const v0 = createClient({ apiKey: process.env.V0_API_KEY }) // Create project and chat const project = await v0.projects.create({ name: 'My App' }) const chat = await v0.chats.init({ type: 'files', files: myFiles, projectId: project.id, }) ``` -------------------------------- ### Get Current Plan Source: https://v0.app/docs/api/platform/packages/v0-sdk Retrieve information about the current subscription plan. ```typescript // Get current plan const plan = await v0.user.getPlan() ``` -------------------------------- ### Configure Client Options Source: https://v0.app/docs/api/platform/packages/v0-sdk Initialize the V0 SDK with custom client options like API key, base URL, timeout, and retries. ```typescript const v0 = new V0({ apiKey: 'your-api-key', baseURL: 'https://api.v0.dev/v1', // Optional timeout: 30000, // Optional, in milliseconds maxRetries: 3, // Optional }) ```