
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeThe key issue you're experiencing is that when deploying to Sanity (via sanity deploy), environment variables need to be prefixed with SANITY_STUDIO_ to be accessible in your Studio application.
When you deploy your Studio to Sanity's hosting, the .env file from your local machine isn't automatically uploaded. Instead, you need to ensure your environment variables follow the correct naming convention and are properly configured for the production environment.
1. Prefix your environment variables with SANITY_STUDIO_
In your .env file (or .env.production for production-specific values), make sure all variables are prefixed:
SANITY_STUDIO_API_PROJECT_ID=your-project-id SANITY_STUDIO_API_DATASET=production SANITY_STUDIO_CUSTOM_VALUE=your-custom-value
2. Access them in your config
Then in your sanity.config.js or sanity.config.ts:
export default defineConfig({
projectId: process.env.SANITY_STUDIO_API_PROJECT_ID,
dataset: process.env.SANITY_STUDIO_API_DATASET,
// other configuration
})3. Environment-specific files
Sanity automatically loads different .env files based on the command:
.env.development - loaded during sanity start (local development).env.production - loaded during sanity build and sanity deployThe environment is determined by the SANITY_ACTIVE_ENV variable, which defaults to development for sanity start and production for sanity deploy.
SANITY_STUDIO_ will be available in your Studio application after deploymentSANITY_AUTH_TOKEN environment variable (without the SANITY_STUDIO_ prefix)You can read more about this in the Sanity Studio environment variables documentation.
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