Skip to main content
The Upstash Redis SDK works seamlessly with Vercel, supporting both Vercel Functions (Node.js runtime) and Vercel Edge Functions.

Installation

Quick Start

API Route (Edge Runtime)

API Route (Node.js Runtime)

Choosing the Right Import

The Upstash Redis SDK automatically works with both Node.js and Edge runtimes:
This single import works for:
  • Vercel Functions (Node.js runtime)
  • Vercel Edge Functions (Edge runtime)
  • The SDK automatically detects the runtime and adjusts accordingly
You don’t need different imports for different runtimes when using Vercel. The default import handles both!

Configuration

The easiest way to configure Redis is using fromEnv(), which automatically reads from environment variables:
This reads from:
  • UPSTASH_REDIS_REST_URL or KV_REST_API_URL
  • UPSTASH_REDIS_REST_TOKEN or KV_REST_API_TOKEN

Using Vercel KV Integration

If you’re using the Vercel KV integration, the environment variables are automatically set as:
  • KV_REST_API_URL
  • KV_REST_API_TOKEN
The SDK automatically falls back to these, so Redis.fromEnv() works out of the box!

Manual Configuration

With Options

Environment Variables

1

Add environment variables to your Vercel project

  1. Go to your project settings in Vercel
  2. Navigate to Environment Variables
  3. Add:
    • UPSTASH_REDIS_REST_URL: Your Redis REST URL
    • UPSTASH_REDIS_REST_TOKEN: Your Redis REST token
2

Or use .env.local for local development

Never commit .env.local to version control. Add it to .gitignore.
3

Or use the Vercel KV Integration

The Vercel KV integration automatically sets up the required environment variables.

Configuration Options

Node.js Runtime (Vercel Functions)

Edge Runtime (Vercel Edge Functions)

The agent option is not supported in Edge Runtime. Use keepAlive: true instead.

Complete Examples

Next.js App Router with Edge Runtime

Next.js App Router with Node.js Runtime

Next.js Pages Router

Runtime Detection

The SDK automatically detects the Vercel runtime:
  • Edge Runtime: Reports as edge-light in telemetry
  • Node.js Runtime: Reports as node@<version> in telemetry
  • Platform: Automatically detected as vercel

Performance Tips

1. Enable Keep-Alive

2. Use Edge Runtime for Global Performance

Edge Functions run closer to your users:

3. Enable Auto-Pipelining

Troubleshooting

”Unable to find environment variable”

Make sure environment variables are set in your Vercel project settings or .env.local file.

Edge Runtime Errors

If using the agent option, remove it for Edge Runtime: