Can't reach Sanity API after standard init with blog preset
This is a frustrating error but usually has a straightforward fix! The "An error occurred while attempting to reach the Sanity API" message typically points to a CORS configuration issue, not an actual API outage.
Here's what to try:
1. Add localhost to your CORS origins
Since you just initialized the project, your localhost development URL likely isn't whitelisted yet. You need to add it in your project settings:
- Go to manage.sanity.io
- Select your project
- Navigate to Settings → API → CORS Origins
- Click Add CORS origin
- Add
http://localhost:3333(or whatever port your Studio is running on) - Important: Check the "Allow credentials" box
- Save
The "Allow credentials" checkbox is crucial - without it, you'll still get CORS errors even with the origin added.
2. Use sanity dev instead of sanity start
In modern Sanity projects (Studio v3+), the recommended command is sanity dev, not sanity start. The dev command starts a development server with live reloading and better performance. Try:
npm run dev
# or
sanity dev3. Check if it's actually an API issue
While rare, sometimes there are actual API issues. You can verify the Sanity API status at status.sanity.io to rule out platform-wide problems.
4. Try the CLI CORS command
You can also add CORS origins via the CLI:
sanity cors add http://localhost:3333 --credentialsThe --credentials flag is equivalent to checking that "Allow credentials" box in the dashboard.
Why this happens
When you initialize a new project, Sanity doesn't automatically whitelist localhost URLs for security reasons. Your browser blocks the requests because the Studio (running on localhost) is trying to make authenticated requests to the Sanity API without proper CORS configuration.
The CORS settings you configure in the Management Dashboard control which domains can access your project data with credentials, so this is a necessary security step for any new project.
Give the CORS configuration a try first - that fixes this issue 99% of the time!
Show original thread22 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.