Sanity Client Error: HTTP 404 "undefined.api.sanity.io" in Remix Tutorial

7 replies
Last updated: Nov 29, 2025
I'm running through
user T
Sanity/Remix tutorial (https://www.sanity.io/guides/remix-run-live-preview ) but have run into an error that I cannot figure out. It says,
Error: HTTP 404 Not Found: <https://undefined.api.sanity.io/v2021-03-25/data/query/production?query=*%5B_type%20%3D%3D%20%22post%22%5D%7B%20_id%2C%20title%2C%20slug%20%7D>
    at getError (/home/h/Documents/webdev/io-remix/frontend/node_modules/picosanity/lib/client.js:91:10)
    at /home/h/Documents/webdev/io-remix/frontend/node_modules/picosanity/lib/client.js:78:11
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async loader (/home/h/Documents/webdev/io-remix/frontend/build/index.js:474:17)
    at async Object.callRouteLoader (/home/h/Documents/webdev/io-remix/frontend/node_modules/@remix-run/server-runtime/data.js:73:14)

AI Update

Looking at your error, the issue is clear: https://undefined.api.sanity.io/... shows that your projectId is undefined, which means your environment variables aren't being loaded properly by Remix.

The Problem

Your Sanity client can't find the project ID, so it's trying to connect to undefined.api.sanity.io instead of something like 79w8op0f.api.sanity.io. This causes the 404 error.

How to Fix It

1. Check your .env file exists and has the correct values

The tutorial you're following creates a .env file in your Remix project root (/remix-live-preview/.env). Make sure it contains your actual project ID, not the example one:

# .env - Replace with YOUR project ID
SANITY_STUDIO_PROJECT_ID="your-actual-project-id"
SANITY_STUDIO_DATASET="production"
SANITY_STUDIO_URL="http://localhost:3333"
SANITY_STUDIO_STEGA_ENABLED="true"

2. Find your actual Project ID

You can find it in your Sanity Studio directory:

  • Open /sanity-live-preview/sanity.config.ts and look for the projectId value
  • Or visit sanity.io/manage and copy it from your project

It should look like "79w8op0f" (8 random characters).

3. Restart your Remix dev server

This is critical! Environment variables only load when the server starts:

# Stop your server (Ctrl+C), then restart:
npm run dev

4. Verify the fix

Add this temporarily to your route to confirm it's working:

export const loader = async () => {
  console.log('Project ID:', process.env.SANITY_STUDIO_PROJECT_ID)
  // ... rest of your loader code
}

Check your terminal - it should print your actual project ID, not undefined.

Still Not Working?

If you're still seeing undefined:

  • Make sure your .env file is at the root of your Remix project (same folder as package.json)
  • Check that you don't have typos in the environment variable names
  • Make sure you're using the modern @sanity/client package (not picosanity which your error mentions - the tutorial uses the newer client)

Once your project ID is correctly loaded, the 404 error will disappear and you'll be able to query your Sanity content!

Show original thread
7 replies

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.

Was this answer helpful?