Joint session with Vercel: How to build intelligent storefronts (May 15th) →

Sanity API Connection Refused Error on Vercel Deployment

9 repliesLast updated: Nov 29, 2025

Hi all, I've recently started working with the sanity cms, and I'm trying to connect it to a site that I've deployed on vercel. I keep getting the following error
GET <http://localhost:3000//api/experience> net::ERR_CONNECTION_REFUSED
. I've checked all my environment variables as well and made sure that my
.env.local
file has the required keys as follows:
#SANITY_PROJECT_ID=your_project_id
#SANITY_DATASET=your_dataset_name
#SANITY_API_TOKEN=your_sanity_api_token
#SANITY_API_VERSION=2021-03-25 // The API version you want to target 
Has anyone encountered this before? If so I'd really appreciate some help with this. I really don't know where I screwed up. Thanks a lot in advance!
AI Update

I can see the issue right away! Your environment variables are all commented out with # symbols at the beginning of each line. In .env files, the # character denotes a comment, which means those lines are being ignored and your variables aren't actually being set.

Remove the # symbols from the beginning of each line in your .env.local file:

SANITY_PROJECT_ID=your_project_id
SANITY_DATASET=your_dataset_name
SANITY_API_TOKEN=your_sanity_api_token
SANITY_API_VERSION=2021-03-25

Also, make sure you replace the placeholder values (your_project_id, your_dataset_name, etc.) with your actual Sanity project credentials. You can find these in your Sanity project dashboard.

A couple of additional things to check:

The ERR_CONNECTION_REFUSED error you're seeing is likely because your API route is trying to connect to Sanity but doesn't have the required credentials (since they were commented out), causing the connection to fail.

Show original thread
9 replies

Was this answer helpful?

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Related contributions