
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeI understand your frustration! The good news is that SANITY_STUDIO_API_DATASET and other SANITY_STUDIO_* environment variables should work in Sanity Studio. Let me help you troubleshoot why they're showing as undefined.
Studio looks for environment-specific files:
.env.development - loaded during sanity start (default).env.production - loaded during sanity build and sanity deployCreate a .env.development file in your Studio root (same directory as sanity.config.ts):
SANITY_STUDIO_API_DATASET=development
SANITY_STUDIO_API_PROJECT_ID=your-project-idAll environment variables that need to be accessible in your Studio code must be prefixed with SANITY_STUDIO_. Without this prefix, the variables won't be passed through to the frontend build.
# ❌ Won't work
API_DATASET=development
# ✅ Will work
SANITY_STUDIO_API_DATASET=developmentEnvironment variables are loaded at build time. If you added or changed .env files while the dev server was running, you must stop and restart sanity start.
Access the variables using process.env:
const dataset = process.env.SANITY_STUDIO_API_DATASET
console.log('Dataset:', dataset) // Debug to see if it's loadingFor your specific use case of setting a logo based on the current dataset, you don't actually need environment variables. You can access the dataset directly from your Studio configuration using the useClient() hook:
import { useClient } from 'sanity'
export function MyLogo() {
const client = useClient({ apiVersion: '2023-05-24' })
const dataset = client.config().dataset
// Use dataset to determine which logo to show
return dataset === 'production'
? <img src="/logo-prod.svg" alt="Production" />
: <img src="/logo-dev.svg" alt="Development" />
}Using useClient() is more reliable because:
sanity.config.ts configuration.env filesIf you have other use cases requiring environment variables, make sure to:
.env.development in your Studio root folder (same directory as sanity.config.ts)SANITY_STUDIO_.env filesprocess.env.SANITY_STUDIO_YOUR_VAR_NAMEIf environment variables still aren't working:
.env file is in the correct location (Studio root, not project root if they're different)console.log('All env vars:', Object.keys(process.env).filter(key => key.startsWith('SANITY_')))process.env.SANITY_ACTIVE_ENV)The official environment variables documentation confirms that the SANITY_STUDIO_ prefix is the correct approach for Sanity Studio v3, and variables are accessed via process.env.
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.
Content operations
Content backend


The only platform powering content operations
By Industry


Tecovas strengthens their customer connections
Build and Share

Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag store