How AI is powering better personalization in e-commerce [with Vercel]. Sign up now

Session does not match project host error with private dataset token

12 repliesLast updated: Nov 29, 2025

Hej,
I’ve made a dataset private and created a token. I worked once, the second time around i’m getting this for my requests:


    body: {
      message: 'Session does not match project host',
      statusCode: 401,
      error: 'Unauthorized'
    },
What does that mean?
AI Update

This error typically means there's a mismatch between the project ID configured in your client and the project where your authentication token was created. The "session" refers to your authenticated request, and "project host" refers to the Sanity project you're trying to access.

Here are the most common causes and solutions:

Check Your Project ID

The most likely issue is that your client configuration is pointing to a different project than the one where you created the token. Verify that:

const client = createClient({
  projectId: 'your-project-id', // Must match the token's project
  dataset: 'your-dataset',
  token: process.env.SANITY_API_TOKEN,
  useCdn: false
})

Common Scenarios That Cause This

Quick Fix

If you're working with multiple Sanity projects, it's helpful to store both the project ID and token together in your environment variables to keep them paired correctly:

SANITY_PROJECT_ID=abc123
SANITY_DATASET=production
SANITY_API_TOKEN=sk...

This way, you can be sure they're always in sync! Since it worked once and then failed, double-check if you recently switched projects or updated any configuration files.

Show original thread
12 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