Error deploying GraphQL API in Sanity v3 project
Based on your configuration, you're running into this issue because in Sanity v3, the way you specify which GraphQL API to deploy has changed. The --dataset and --tag flags still exist but they're causing conflicts when you have multiple workspace-based GraphQL API configurations.
The solution is to use the --api flag instead, which is the v3 way of targeting specific GraphQL deployments when you have multiple workspaces configured.
In your sanity.cli.ts, you've defined two GraphQL APIs based on workspaces:
graphql: [
{
workspace: "production",
},
{
workspace: "test",
},
]However, these configurations need explicit IDs to be targetable. Update your sanity.cli.ts to include id properties:
export default defineCliConfig({
api: {
projectId: "xxxxxx",
},
graphql: [
{
id: "production-api",
workspace: "production",
},
{
id: "test-api",
workspace: "test",
},
],
});Now you can deploy specific APIs using:
sanity graphql deploy --api test-apior
sanity graphql deploy --api production-apiThe reason --dataset and --tag are causing errors is that when you have workspace-based configurations, each workspace already maps to its corresponding dataset from your sanity.config.ts. Using --dataset and --tag tries to override this for ALL APIs, which creates duplicate configurations for the same dataset/tag combination - hence the error "Multiple GraphQL APIs with the same dataset and tag found (test/default)".
As you discovered, running sanity graphql deploy without flags works because it prompts you interactively for each workspace. But using the --api flag with explicit IDs gives you the programmatic control you're looking for while respecting the workspace-based configuration pattern in v3.
The CLI GraphQL documentation confirms that --api <api-id> is the recommended approach for deploying specific APIs in multi-workspace setups.
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.