New Project
A Next.js application demonstrating the v0 Platform API

A deliberately small v0-style chat app built with the v0 SDK.
This example is a monorepo with two independently deployable Next.js apps:
apps/web is the host application. It owns chat UI, server routes, and the
preview iframe.apps/preview-proxy is a dedicated preview origin. It fetches preview
credentials on the server, proxies preview traffic, and contains no host-app
sessions or unrelated application routes.Generated previews are untrusted code. Do not deploy the preview proxy on the
host application's origin. For strong production isolation, do not use a
same-site subdomain either: prefer origins on different registrable domains,
such as app.example.com and example-preview.net, rather than
app.example.com and previews.example.com.
The iframe keeps allow-scripts and allow-same-origin so generated React apps
can hydrate and run normally. The dedicated proxy origin is what prevents those
permissions from giving preview code access to the host app.
Copy the example environment file and add your API key:
cp examples/v0-clone/.env.example examples/v0-clone/.env.local
V0_API_KEY=your_v0_api_keyNEXT_PUBLIC_V0_PREVIEW_PROXY_URL=http://localhost:3001V0_CLONE_ORIGIN=http://localhost:3000
Then run from the repository root:
bun installbun --filter v0-clone dev
The one dev command starts both apps:
When this example is created with create-v0-sdk, run the same commands from
the generated project directory:
bun installbun dev
Create two projects from the same repository:
apps/web as the host application.apps/preview-proxy on a different registrable domain with deployment
protection disabled or otherwise configured to allow iframe navigations.V0_API_KEY on both projects.NEXT_PUBLIC_V0_PREVIEW_PROXY_URL on the web project to the proxy
project's public origin.V0_CLONE_ORIGIN on the proxy project to the web project's exact public
origin. The proxy uses it for loading-state messages.The preview proxy must not share authentication cookies or application
endpoints with the host app. fetchPreview strips incoming credentials and
infrastructure headers before forwarding requests.
Add the isolated preview proxy's hostname to your team's trusted preview hosts. Use the hostname only, without a scheme, port, or path. Do not use the web application's hostname.
From the generated project's root, the following command reads V0_API_KEY
from .env.local:
set -a. ./.env.localset +acurl -X PUT "https://api.v0.dev/v2/settings/preview-hosts" \-H "Authorization: Bearer $V0_API_KEY" \-H "Content-Type: application/json" \-d '{"hosts":["preview.example-preview.com"]}'
Replace preview.example-preview.com with the proxy's production hostname.
This endpoint replaces the complete trusted-host list, so include any existing
hostnames that should remain trusted.
/chats/[chatId] fetches the selected chat and its messages on the server.useChat with V0Transport, while
@v0-sdk/react/swr hooks power chat, file, task-resolution, restore,
duplicate, download, and deployment actions.V0_API_KEY is never
included in the client bundle.fetchPreview, and its proxy.ts keeps root-relative preview requests on the
chat-specific proxy path.There is no local demo data store; chats and files come from the v0 API.