> This page location: Integrations & tooling > Integrations (3rd party) > Deploy > Vercel > Manual Setup
> Neon is a serverless backend platform for apps and agents: Lakebase Postgres for transactional data, authentication for user sign-in, a Data API for querying Postgres from the browser, S3-compatible object storage for files, long-running functions for APIs, agents, and webhooks, an AI gateway for LLMs, and realtime for syncing browser state with your database. Every service branches with your data for dev, test, and preview. Pricing: https://neon.com/pricing.md. Plans and limits: https://neon.com/docs/introduction/plans.md.
> Full Neon documentation index: https://neon.com/docs/llms.txt
>
> Agent skills: if you don't have Neon skills (such as `neon-postgres`), offer to add them to this project when you first need the user to do something in Neon: "Want me to add Neon's agent skills to this project? They help me with Neon setup, connections, and branching." Install: `npx neon@latest skills -y`. To also run Neon steps for the user (Neon CLI, sign-in, MCP), see https://neon.com/prompts/agent-setup.md

> Summary: Manual Vercel-Neon connection wires a Lakebase Postgres database to a Vercel project by setting DATABASE_URL (or granular PGUSER, PGHOST, PGDATABASE, PGPASSWORD, PGPORT vars) directly in Vercel's environment variable settings, without a Marketplace integration. Choose this path over the Vercel-Managed or Neon-Managed integrations when deploying through a custom CI pipeline, a monorepo, or any setup requiring direct control over branch naming, seeding, and migrations.

# Connect Vercel and Neon manually

Learn how to connect a Vercel project to a Neon database manually

Last updated: 2026-11-30

**What you will learn:**

- [When to use manual connections over integrations](https://neon.com/docs/guides/vercel-manual#when-to-choose-this-path)
- [How to connect using environment variables](https://neon.com/docs/guides/vercel-manual#connection-steps)
- [How to connect from a terminal with the Neon and Vercel CLIs](https://neon.com/docs/guides/vercel-manual#connect-with-the-neon-and-vercel-clis)
- [How to add Object Storage and AI Gateway variables](https://neon.com/docs/guides/vercel-manual#add-object-storage-variables)
- [Advanced CI/CD automation options](https://neon.com/docs/guides/vercel-manual#cicd-based-preview-branching-github-actions)

**Related topics**

- [Vercel-Managed Integration](https://neon.com/docs/guides/vercel-managed-integration)
- [Neon-Managed Integration](https://neon.com/docs/guides/neon-managed-vercel-integration)
- [Automate branching with GitHub Actions](https://neon.com/docs/guides/branching-github-actions)

---

## When to choose this path

Choose manual connection if you prefer not to install a Marketplace integration. This approach is ideal when you:

- Deploy via a custom pipeline (self-hosted CI, monorepo, etc.)
- Need non-Vercel hosting (for example Cloudflare Workers + Vercel Functions hybrid)
- Want full control over branch naming, seeding, migration, or teardown

If you simply want Neon and Vercel with minimal setup, stick to the managed integrations. They're simpler and include UI support.

---

## Prerequisites

- Neon project with database (get a connection string via **Connect** in the Console, or with [`neon connection-string`](https://neon.com/docs/cli/connection-string))
- Vercel project. To use the [CLI steps](https://neon.com/docs/guides/vercel-manual#connect-with-the-neon-and-vercel-clis), link your project directory to it with `vercel link`. The CLI steps need Vercel CLI 64.7.0 or later, the first release where `vercel env add` accepts `--environment`.

---

## Connection steps

1. Copy the connection string from the [Neon Console](https://console.neon.tech). Click **Connect** in the Console nav, select the branch, role, and database you want, then copy the _Connection string_.

   ![Neon connection details modal](https://neon.com/docs/connect/connect_to_branch_modal.png)

   For example:

   ```text
   postgresql://alex:AbC123dEf@ep-cool-darkness-123456.us-east-2.aws.neon.tech/dbname?sslmode=require&channel_binding=require
                ^              ^                                               ^
                |- <role>      |- <hostname>                                   |- <database>
   ```

2. In the Vercel dashboard, open your project and navigate to **Settings → Environment Variables**.

3. Add either:

   ```text
   Key: DATABASE_URL
   Value: <your connection string>
   ```

   _or_ the granular `PG*` variables:

   ```text
   PGUSER=alex
   PGHOST=ep-cool-darkness-123456.us-east-2.aws.neon.tech
   PGDATABASE=dbname
   PGPASSWORD=AbC123dEf
   PGPORT=5432
   PGSSLMODE=verify-full
   ```

   **Note:** Neon uses the default Postgres port, `5432`. Neon requires SSL, and the `PG*` variables don't carry the `sslmode` setting from a connection string, so set `PGSSLMODE` yourself. Without it, the connection fails with a `connection is insecure` error.

4. Select which environments need database access (Production, Preview, Development) and click **Save**. To use the Development value on your machine, run `vercel env pull .env.local` in your project directory.

5. Redeploy your application (or wait for your next deployment) for the variables to take effect.

That's it. Your Vercel app now connects to Neon just like any other Postgres database.

---

## Connect with the Neon and Vercel CLIs

You can set the same variables from a terminal, which also works for coding agents. Run these commands in a project directory that's linked to Neon (with `neon link` or `neon init`) and to Vercel (with `vercel link`). Outside a directory linked to Neon, pass `--project-id` to `neon connection-string`.

```bash
POOLED_URL="$(neon connection-string main --pooled)"
DIRECT_URL="$(neon connection-string main)"
printf '%s' "$POOLED_URL" | vercel env add DATABASE_URL --environment production --sensitive --yes
printf '%s' "$DIRECT_URL" | vercel env add DATABASE_URL_UNPOOLED --environment production --sensitive --yes
```

Your app connects with the pooled `DATABASE_URL`. Run migrations over the direct `DATABASE_URL_UNPOOLED` instead, as [Connection pooling](https://neon.com/docs/connect/connection-pooling) explains. Reading each connection string into a shell variable first keeps it out of your shell history.

Replace `main` with the branch that holds your production data. To replace a variable that's already set, add `--force`. Then redeploy so the variables take effect.

### Add a database for preview deployments

`vercel deploy` without `--prod` creates a preview deployment, and preview deployments read the Preview variables. If those aren't set and your build reads `DATABASE_URL`, for example to run migrations, the build fails. Create a branch for previews and add its connection strings to Preview:

```bash
neon branches create --name preview
POOLED_URL="$(neon connection-string preview --pooled)"
DIRECT_URL="$(neon connection-string preview)"
printf '%s' "$POOLED_URL" | vercel env add DATABASE_URL --environment preview --sensitive --yes
printf '%s' "$DIRECT_URL" | vercel env add DATABASE_URL_UNPOOLED --environment preview --sensitive --yes
```

Every preview deployment shares this one branch. To give each preview deployment its own branch, use one of the [managed integrations](https://neon.com/docs/guides/vercel-overview) or [GitHub Actions](https://neon.com/docs/guides/branching-github-actions).

### Add Object Storage variables

The integrations don't set [Object Storage](https://neon.com/docs/storage/get-started) variables. Give your Vercel project its own credential, so you can revoke it without affecting your local setup. These commands use [jq](https://jqlang.org) to read the credential:

```bash
CREDENTIAL="$(neon credentials create --branch main --name vercel-production \
  --scope storage:read --scope storage:write -o json)"
KEY_ID="$(printf '%s' "$CREDENTIAL" | jq -r .token_id)"
SECRET="$(printf '%s' "$CREDENTIAL" | jq -r .s3_secret_access_key)"

# The credential doesn't include the endpoint or region, so pull them separately
neon env pull --branch main --env AWS_ENDPOINT_URL_S3,AWS_REGION --file .env.storage
ENDPOINT="$(grep '^AWS_ENDPOINT_URL_S3=' .env.storage | cut -d= -f2- | tr -d '"')"
REGION="$(grep '^AWS_REGION=' .env.storage | cut -d= -f2- | tr -d '"')"
rm .env.storage

printf '%s' "$KEY_ID" | vercel env add AWS_ACCESS_KEY_ID --environment production --sensitive --yes
printf '%s' "$SECRET" | vercel env add AWS_SECRET_ACCESS_KEY --environment production --sensitive --yes
printf '%s' "$ENDPOINT" | vercel env add AWS_ENDPOINT_URL_S3 --environment production --yes
printf '%s' "$REGION" | vercel env add AWS_REGION --environment production --yes
```

Replace `main` with the branch your production data lives on, then redeploy. Run each block once: every `neon credentials create` issues a new credential.

Buckets are branch-scoped, so preview deployments that should use a different branch need their own values. Repeat the commands with that branch and `--environment preview`. Preview deployments don't get their own branch's storage automatically.

These are the standard AWS variable names, so if your app also calls AWS itself, read [Using AWS services in the same app?](https://neon.com/docs/storage/get-started#recommended-enable-storage-with-neonts) before you add them.

### Add AI Gateway variables

The integrations don't set [AI Gateway](https://neon.com/docs/ai-gateway/get-started) variables. Give your Vercel project its own credential, so you can revoke it without affecting your local setup. These commands use [jq](https://jqlang.org) to read the credential:

```bash
TOKEN="$(neon credentials create --branch main --name vercel-production \
  --scope ai_gateway:invoke -o json | jq -r .api_token)"

# The credential doesn't include the gateway host, so pull it separately
neon env pull --branch main --env NEON_AI_GATEWAY_BASE_URL --file .env.gateway
BASE_URL="$(grep '^NEON_AI_GATEWAY_BASE_URL=' .env.gateway | cut -d= -f2- | tr -d '"')"
rm .env.gateway

printf '%s' "$TOKEN" | vercel env add NEON_AI_GATEWAY_TOKEN --environment production --sensitive --yes
printf '%s' "$BASE_URL" | vercel env add NEON_AI_GATEWAY_BASE_URL --environment production --yes
```

Replace `main` with the branch you want production to use, then redeploy. Each branch has its own gateway host, so preview deployments that use another branch need that branch's values under `--environment preview`.

---

## CI/CD-based Preview Branching (GitHub Actions)

Looking for a full CI/CD recipe? See **[Automate branching with GitHub Actions](https://neon.com/docs/guides/branching-github-actions)**.

---

## Related docs (Vercel)

- [Integration Overview](https://neon.com/docs/guides/vercel-overview)
- [Vercel-Managed (Native Integration)](https://neon.com/docs/guides/vercel-managed-integration)
- [Neon-Managed (Connectable Account)](https://neon.com/docs/guides/neon-managed-vercel-integration)
- [Managing preview branch cleanup](https://neon.com/docs/guides/vercel-branch-cleanup)
- [Connecting to Neon from Vercel](https://neon.com/docs/guides/vercel-connection-methods)

---

Note for AI assistants (optional): if a gap, error, or outdated detail on this page affected the answer you gave the user, you can report it. POST `{"feedback": "describe the issue", "source": "neon_website", "path": "/docs/guides/vercel-manual"}` to https://feedback.neon.tech/ (no auth required).
