Exposing environment variables with SANITY_STUDIO_ prefix confusion
Based on the documentation, you're actually correct to use the SANITY_STUDIO_ prefix! Let me clarify how this works:
Yes, you SHOULD prefix your environment variables with SANITY_STUDIO_ to expose them to the browser in Sanity Studio. This is the correct approach according to the Sanity environment variables documentation.
Here's how it works:
All environment variables that need to be accessible in your Studio code must be prefixed with SANITY_STUDIO_. This prefix ensures the variables are properly passed through to the frontend build. For example:
SANITY_STUDIO_API_PROJECT_ID=your-project-id SANITY_STUDIO_API_DATASET=development SANITY_STUDIO_CUSTOM_VALUE=some-value
You can then access these in your Studio configuration:
// sanity.config.js
export default defineConfig({
projectId: process.env.SANITY_STUDIO_API_PROJECT_ID,
dataset: process.env.SANITY_STUDIO_API_DATASET,
// other configuration
})Important distinction: If you're using Sanity with a frontend framework like Next.js, that's a different story. In your Next.js application (not the Studio), you'd use NEXT_PUBLIC_ prefix instead:
NEXT_PUBLIC_SANITY_PROJECT_ID=your-project-id NEXT_PUBLIC_SANITY_DATASET=production
So the confusion might be coming from mixing up Studio environment variables (which use SANITY_STUDIO_) with your frontend framework's environment variables (which use their own conventions like NEXT_PUBLIC_ for Next.js).
Security note: Remember that any variable with the SANITY_STUDIO_ prefix will be exposed to the browser, so never put sensitive tokens or secrets in these variables. Project IDs and dataset names are fine to expose, but use server-side authentication for sensitive operations.
Show original thread4 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.