PatchVault › Errors › @vercel/kv & @vercel/postgres → Upstash + Neon

@vercel/kv: Missing required environment variables KV_REST_API_URL and KV_REST_API_TOKEN

The default kv client in @vercel/kv throws this the first time it is used if either variable is missing from process.env at runtime.

Check your code free (runs in your browser)

The box is pre-filled with a sample that triggers this error. Paste your own file to check it. Nothing leaves this page.

Or scan your whole repo locally (free, stdlib Python, read-only):

python3 <(curl -fsSL https://patchvault-81y.pages.dev/starters/vercel-kv-scan.py) .
Get the @vercel/kv & @vercel/postgres → Upstash + Neon auto-fixer: $9 one-time

Why it happens

The variables are not set for that environment, the code runs on the client (prefixed env vars are not provided), or a bundler (Vite/Rollup) replaced process.env. After the move to Upstash, many projects have UPSTASH_REDIS_REST_URL / _TOKEN instead.

Manual fix

// read whichever pair your project actually has
import { Redis } from '@upstash/redis'
export const kv = new Redis({
  url: process.env.UPSTASH_REDIS_REST_URL ?? process.env.KV_REST_API_URL!,
  token: process.env.UPSTASH_REDIS_REST_TOKEN ?? process.env.KV_REST_API_TOKEN!,
})

Verify

Re-run your install/build and re-scan the file above. The finding should be gone. The paid fixer applies the same change across a repo: --dry-run shows the diff, --apply keeps a .bak of each file, and --rollback restores them.

Sources

Related errors

Full guide and free terminal scanner: @vercel/kv & @vercel/postgres → Upstash + Neon. Last checked 2026-10-31.