Sanity 400 bad request error: "object or function expected" overnight
Based on my investigation, Sanity's status page shows all systems operational with no reported outages or incidents in the last 24 hours. The error message you're seeing - "object or function expected" with a 400 Bad Request - is actually quite unusual for Sanity API responses, which typically return structured JSON error messages.
Here are a few things to check:
1. Check if you're using third-party APIs in your build The error message "object or function expected" sounds more like a JavaScript runtime error or a response from a different API service. If your builds use services like OpenAI, Azure, or other third-party APIs, check their status pages as this error pattern is more consistent with those services.
2. Verify your Sanity client configuration Check if there have been any changes to:
- Your API tokens or credentials
- Project ID or dataset name
- API version in your client configuration
- Any environment variables that might have expired or changed
3. Look at recent API version changes
Sanity recently changed the default API perspective from raw to published in API version 2025-02-19. If your builds recently started using this API version without explicitly setting a perspective, you might be getting unexpected responses. Try explicitly setting the perspective in your client:
const client = createClient({
// ... other config
perspective: 'raw', // or 'published'
apiVersion: '2024-01-01' // use a specific version
})4. Check for GROQ query syntax issues
If you're using newer tooling, make sure your GROQ queries are wrapped with defineQuery if you're using TypeGen, as this is now required.
5. Inspect the actual error response The "object or function expected" error is very generic. Can you check:
- The full error response body
- Which specific endpoint is returning this error
- Your network tab to see the actual HTTP response
Since your builds worked 24 hours ago and Sanity's status page shows no incidents, this is likely either a configuration issue on your end or a problem with a third-party service your builds depend on. If you can share more details about which specific requests are failing (the actual API endpoint, request payload, and full error response), that would help narrow down the issue!
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.