Hello, quick question - is it safe to commit my `projectId`?

4 replies
Last updated: Dec 30, 2020
Hello, quick question - is it safe to commit my
projectId
?
AI Update

Yes, it's completely safe to commit your projectId to version control!

Your projectId is meant to be public information. It will be visible everywhere in your final code—including all your queries that run client-side. Think of it like a domain name rather than a secret credential.

If your dataset is set to public visibility, you should assume that everything in it (along with the projectId) is visible to anyone. The projectId itself doesn't grant any write access or special permissions—those are controlled by authentication tokens.

While you could technically store the projectId as an environment variable to avoid hardcoding it, your final bundled application would still expose it anyway since it needs to make API requests to Sanity's CDN.

What you should keep secret:

  • API tokens with write access
  • Your dataset name (if you want to keep it private)
  • Any authentication credentials

What's safe to commit:

  • projectId
  • Public dataset names
  • Read-only tokens for public datasets

One small detail: even if your dataset is public, documents with _id values that include a path (like drafts.) will still be hidden from public access, as explained in Sanity's ID documentation.

Yes. It will be everywhere in your final code—including all your queries. If your dataset is public, assume everything in it (as well as the projectId) are visible.
Excellent, thank you! Just went back to a Sanity project and saw it was just there, made me wonder 🙂 Thanks!
I suppose technically you could write code where the projectId is an environment variable and isn't actually hardcoded, but your final project would still make it available.
Yes, consider it as a domain.
Small detail, even if your dataset is public, documents with their _id on a path will still be hidden from public.
https://www.sanity.io/docs/ids

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?