@vercel/drives
The TypeScript SDK for Vercel Drives. Create, list, fork, and delete persistent
storage that you can mount in Vercel Sandbox.
The default maximum size is 1 TiB (1 GiB for Hobby) and can be increased to 16 TiB or more on request. See Mount a drive in a sandbox and the documentation for more details.
Getting started
Install the SDK:
pnpm add @vercel/drives
Link your Vercel project and download a development OIDC token to .env.local:
npx vercel link
npx vercel env pull
Create an index.mts file:
import { Drive } from "@vercel/drives";
const drive = await Drive.getOrCreate({
name: "my-drive",
region: "iad1",
maxSize: 1 * 1024 ** 4, // 1 TiB
});
console.log(drive.driveId, drive.name, drive.region);
Run it:
node --env-file .env.local index.mts
Authentication
Vercel OIDC token
The SDK uses Vercel OIDC when available. Enable OIDC
for your project to authenticate on Vercel. For local development, load the
.env.local file as shown above.
In an interactive local session, the SDK can also use Vercel CLI credentials or
start a device authorization flow.
Access token
To authenticate outside Vercel without OIDC, create an access token
scoped to your team. Pass the token, team ID, and project ID to the SDK method:
import { Drive } from "@vercel/drives";
const drive = await Drive.getOrCreate({
name: "my-drive",
token: process.env.VERCEL_TOKEN!,
teamId: process.env.VERCEL_TEAM_ID!,
projectId: process.env.VERCEL_PROJECT_ID!,
});
Usage
Get an existing drive
Drive.get() retrieves a drive by name and throws if it does not exist.
Drive.getOrCreate() creates the drive if needed.
import { Drive } from "@vercel/drives";
const drive = await Drive.get({ name: "my-drive" });
List drives
Drive.list() returns the first page and a paginator. Use for await to read
drives across all pages:
import { Drive } from "@vercel/drives";
const drives = await Drive.list({
limit: 20,
sortBy: "name",
sortOrder: "asc",
});
for await (const drive of drives) {
console.log(drive.name, drive.driveId);
}
Use drives.pages() to iterate over pages, or await drives.toArray() to collect
all drives into an array.
Fork and delete a drive
Fork a drive into a new, separate drive. Delete the fork when you no longer
need it:
import { Drive } from "@vercel/drives";
const drive = await Drive.get({ name: "my-drive" });
const fork = await drive.fork({ name: "my-drive-fork" });
await fork.delete();
Mount a drive in a sandbox
Install @vercel/sandbox alongside @vercel/drives:
pnpm add @vercel/sandbox
Create the sandbox in the same project and region as the drive:
import { Drive } from "@vercel/drives";
import { Sandbox } from "@vercel/sandbox";
const drive = await Drive.getOrCreate({ name: "my-drive", region: "iad1" });
const sandbox = await Sandbox.create({
region: drive.region,
mounts: {
"/data": drive,
},
});
Mount paths must be absolute and must not overlap. To mount a read-only snapshot,
use drive.snapshot() as the mount value.