Engineering notes — ExplainersVercel Drives CLI and TypeScript SDK in a real migration
How to use the new Vercel Drives CLI, TypeScript SDK, and REST API to migrate an existing Next.js app off ad-hoc file storage like KV, Blob, or S3.
Vercel just made Drives feel like a first-class product: there's now a vercel drives CLI, standalone SDKs, a REST API, and Drive-specific permissions. That’s enough to treat Drives as the primary file store in a Next.js app instead of a sidecar behind Sandboxes.
I’ll walk through how I’d migrate an existing Next.js app that currently uses a mix of KV, Blob, and S3 to Vercel Drives, using the CLI, TypeScript SDK and REST API with concrete patterns for permissions.
What actually changed in Vercel Drives
Vercel’s changelog describes four new ways to work with Drives:
"You can now create, list, fork, and delete Vercel Drives with the new vercel drives commands or standalone SDKs for TypeScript ( @vercel/drives ) and Python ( vercel-drives ). Drives also have a REST API at /v1/drives and Drive-specific permissions, so managing them no longer requires Sandbox APIs or permissions."
A few important constraints from the same post:
- You need the latest Vercel CLI, and your project must be linked with
vercel linkbefore using the new commands. - The TypeScript SDK ships as
@vercel/driveson npm, and the Python SDK asvercel-driveson PyPI. - Drives still mount into Vercel Sandboxes, and existing Sandbox-based code keeps working.
- Drives now have their own pages in the Vercel dashboard and Observability.
- They’re available on Hobby, Pro and Enterprise.
So the new piece isn’t Drives themselves, it’s that you can treat Drives as an independent resource with their own CLI, SDKs, REST API and permissions, without going through Sandbox APIs.
The rest of this post is my interpretation of how to use that in a migration, using illustrative TypeScript and REST examples. Vercel’s post doesn’t specify method names, request bodies or permission schemas, so any specific API shapes below are patterns you can adapt once you’re looking at the official Drives docs.
Setting up: CLI and TypeScript SDK
In a Next.js monorepo deployed on Vercel, the starting point is the CLI and SDK install Vercel describes.
Trying it, in the Vercel-linked project root:
vercel link
npm install @vercel/drivesWith that in place, you can:
- Use the
vercel drivesfamily of commands to create, list, fork and delete drives in the project. - Import the
@vercel/drivesTypeScript SDK directly in your Next.js API routes, server actions, or Vercel Functions.
From a migration perspective, that’s enough to:
- Create one or more Drives to replace whichever storage you’re using today.
- Wire new read/write paths to those Drives with the SDK.
- Optionally expose Drives to other services via the
/v1/drivesREST API.
If you’re already using Vercel Blob TTL, some of the retention thinking from my earlier write-up on using Vercel Blob TTL for automatic file deletion still applies. You’ll just be enforcing it in a different storage layer.
Case study: migrating off ad-hoc storage
Picture a typical Next.js SaaS that grew quickly:
- Small documents and JSON blobs live in Vercel KV.
- User uploads go to Vercel Blob in one part of the app and S3 in another.
- A background worker in a separate service runs exports and writes results to S3.
Over time, file access logic sprawls:
- Some code talks to KV directly.
- Some uses Blob URLs.
- Some constructs S3 keys by hand.
Vercel Drives, with their own CLI, SDK and REST API, give you a chance to converge on one abstraction for “files I care about” while still keeping Sandboxes as an execution detail.
One migration plan I’d consider:
- Introduce Drives as the canonical file store for new features first.
- Backfill existing files from KV/Blob/S3 into Drives asynchronously.
- Switch read paths to prefer Drives, then fall back to legacy storage during the cutover.
- Delete legacy storage paths once metrics say you’re not using them.
The rest of this piece focuses on step 1 and 3: how to actually use the new tools from Next.js and other services.
How I’d use the Vercel Drives CLI
Vercel says you can:
"create, list, fork, and delete Vercel Drives with the new vercel drives commands"
For a migration, I’d use that to:
- Create a staging drive and production drive for the app.
- Optionally create per-tenant drives if you have strong isolation requirements.
- Script drive creation as part of environment bootstrap, the same way you might provision a database.
I wouldn’t guess specific subcommands here. I’d keep one small script in the repo documenting the set of Drives you expect and the manual steps you ran with vercel drives to create them. That way a new engineer doesn’t have to reverse-engineer ad-hoc resources in the dashboard.
The key benefit is lifecycle: fork lets you copy a Drive, which is useful when you want a realistic staging copy, and delete gives you a clear cleanup step per environment rather than scattering cleanup across KV tables and S3 buckets.
TypeScript SDK usage in a Next.js route (illustrative)
With @vercel/drives installed, you can bring Drives into the same TypeScript environment as your Next.js routes and Vercel Functions.
Here’s an illustrative pattern, not a reference:
// app/api/files/route.ts
import { NextRequest, NextResponse } from "next/server";
import { drives } from "@vercel/drives"; // illustrative import
// Helper to get the drive you want to use for this environment
function getAppDrive() {
// This might look up a drive by name or ID from env/config
return drives.fromEnv("APP_DRIVE_ID"); // illustrative method
}
export async function POST(req: NextRequest) {
const drive = getAppDrive();
const formData = await req.formData();
const file = formData.get("file");
if (!(file instanceof File)) {
return NextResponse.json({ error: "Missing file" }, { status: 400 });
}
// Example: write into the drive under a generated key
const key = `uploads/${crypto.randomUUID()}`;
// Illustrative API: actual method names may differ in docs
await drive.write(key, await file.arrayBuffer(), {
contentType: file.type,
});
return NextResponse.json({ key });
}
export async function GET(req: NextRequest) {
const drive = getAppDrive();
const { searchParams } = new URL(req.url);
const key = searchParams.get("key");
if (!key) {
return NextResponse.json({ error: "Missing key" }, { status: 400 });
}
// Illustrative read
const object = await drive.read(key);
if (!object) {
return new NextResponse("Not found", { status: 404 });
}
return new NextResponse(object.body, {
headers: {
"Content-Type": object.contentType ?? "application/octet-stream",
},
});
}The structural pieces that do carry over to the real SDK:
- Centralizing drive selection (per environment or per tenant) in one helper so you don’t sprinkle IDs across routes.
- Treating the drive as your primary source of truth for file content, with KV or Postgres only storing metadata and keys.
- Using TypeScript types to make it hard to accidentally reach for legacy storage.
This is the layer where you can fold in concerns like request limits from Vercel Functions; if you’re uploading large files, the patterns from my post on the Vercel Functions 20MiB request body limit still matter around your upload endpoint.
Using the /v1/drives REST API for other services
Vercel says Drives now have:
- "a REST API at /v1/drives"
That gives you an integration path for:
- Background workers not running as Vercel Functions.
- Other language services that don’t use the TypeScript or Python SDKs.
- Third-party tooling you control, like an internal migration tool.
Here’s an illustrative fetch from a Node service:
// scripts/backfill-to-drives.ts
import fetch from "node-fetch";
const DRIVE_ID = process.env.DRIVE_ID!;
const VERCEL_TOKEN = process.env.VERCEL_TOKEN!; // e.g. a token with Drive access
async function listDriveObjects(cursor?: string) {
const url = new URL("https://api.vercel.com/v1/drives/objects");
url.searchParams.set("driveId", DRIVE_ID);
if (cursor) url.searchParams.set("cursor", cursor);
const res = await fetch(url, {
headers: {
Authorization: `Bearer ${VERCEL_TOKEN}`,
},
});
if (!res.ok) throw new Error(`Failed to list objects: ${res.status}`);
return res.json();
}
async function main() {
let cursor: string | undefined;
do {
const page = await listDriveObjects(cursor);
for (const object of page.items) {
// Run your migration logic per object
console.log(object.key);
}
cursor = page.nextCursor;
} while (cursor);
}
main().catch((err) => {
console.error(err);
process.exit(1);
});Treat this as a sketch of how you’d structure a backfill tool, not a drop-in example; the real paths, query parameters, and response shapes will come from the Drives documentation linked from Vercel’s post.
For a Next.js-heavy stack, I’d still keep most file traffic on the TypeScript SDK and reserve /v1/drives for infrastructure scripts or services that can’t use the SDK.
Permissions: combining Drive-specific access with app rules
The most important line for security is that Drives now have:
- "Drive-specific permissions, so managing them no longer requires Sandbox APIs or permissions."
That means you can:
- Grant access at the level of a Drive as a resource, instead of relying only on which Sandbox is mounting it.
- Avoid wiring everything through generic Sandbox permissions for management operations like create or delete.
In a multi-tenant Next.js app, I’d still layer app-level authorization on top:
- Drive-level permissions in Vercel control which systems can see or modify a given Drive.
- Application-level permissions in your code control which users can read or write which keys inside that Drive.
Here’s an illustrative pattern for the second layer in an app router API route:
// app/api/files/[key]/route.ts
import { NextRequest, NextResponse } from "next/server";
import { drives } from "@vercel/drives"; // illustrative
import { getSessionUser } from "@/lib/auth"; // your auth helper
import { canAccessFile } from "@/lib/permissions"; // your RLS-like logic
const drive = drives.fromEnv("APP_DRIVE_ID");
export async function GET(
req: NextRequest,
{ params }: { params: { key: string } }
) {
const user = await getSessionUser(req);
if (!user) return new NextResponse("Unauthorized", { status: 401 });
const key = params.key;
const allowed = await canAccessFile({ userId: user.id, key });
if (!allowed) return new NextResponse("Forbidden", { status: 403 });
const object = await drive.read(key); // illustrative
if (!object) return new NextResponse("Not found", { status: 404 });
return new NextResponse(object.body, {
headers: {
"Content-Type": object.contentType ?? "application/octet-stream",
},
});
}canAccessFile is where you implement whatever ownership or role-based logic you’d normally put into database row-level security. If you come from Supabase work, this will feel similar to RLS policy checks you’d write as SQL; I talk more about that kind of access control in my Angel Host case study.
The combination of Drive-level permissions and app-level authorization gives you two walls: even if an app bug exposes a route, the Drive’s own permissions still limit how and where it can be reached.
When I wouldn’t migrate to Drives yet
A few cases where I’d hold off or move more slowly:
- You haven’t outgrown existing storage. If a handful of Blob buckets with clear conventions already work, you don’t need a storage migration just because a new API exists.
- You don’t have time for access control design. Drives add a permission surface. If your current stack already centralizes access in something like Postgres with strong RLS, duplicating rules too quickly can go wrong.
- Your background workers are tightly coupled to S3. If you have years of tooling built around S3 semantics, rewrite cost might not pay off immediately. In that case, I’d start with greenfield features on Drives instead of full migration.
I’d also wait for your team to read the official Drives documentation before committing, and line up a concrete migration plan based on how your app stores and reads files today.
Vercel’s new Drives CLI, TypeScript SDK and /v1/drives REST API are enough to treat Drives as the main file system for a Next.js product, instead of bolting them onto Sandboxes. Used well, they give you a single place to manage file lifecycle, plus clearer permissions and observability. If you’d like help planning or executing a migration like this in a live app, I take on this kind of work as a Next.js developer.
Sources
- Vercel changelog — Vercel Drives adds CLI commands and standalone SDKs: https://vercel.com/changelog/vercel-drives-adds-cli-commands-and-standalone-sdks