mastra-ai/mastra · error · Error

You have no organizations. Please create one at ${MASTRA_STU

Error message

You have no organizations. Please create one at ${MASTRA_STUDIO_URL}

What it means

resolveOrg fetches the caller's organizations from the Mastra Studio API during deploy. If the authenticated account belongs to zero organizations, deployment cannot proceed (a project must live inside an org), so the command throws and points you at MASTRA_STUDIO_URL to create one.

Source

Thrown at packages/cli/src/commands/studio/deploy.ts:237

  // 3. credentials currentOrgId
  const currentOrgId = await getCurrentOrgId();
  const orgs = await fetchOrgs(token);

  if (currentOrgId) {
    const match = orgs.find(o => o.id === currentOrgId);
    if (match) {
      return { orgId: match.id, orgName: match.name };
    }
  }

  // 4. Auto-select if only 1 org
  if (orgs.length === 1) {
    return { orgId: orgs[0]!.id, orgName: orgs[0]!.name };
  }

  // 5. Interactive picker
  if (orgs.length === 0) {
    throw new Error(`You have no organizations. Please create one at ${MASTRA_STUDIO_URL}`);
  }

  const selected = await p.select({
    message: 'Select an organization',
    options: orgs.map(o => ({ value: o.id, label: `${o.name} (${o.id})` })),
  });

  if (p.isCancel(selected)) {
    p.cancel('Deploy cancelled.');
    process.exit(0);
  }

  const selectedOrg = orgs.find(o => o.id === selected)!;
  return { orgId: selectedOrg.id, orgName: selectedOrg.name };
}

/* ------------------------------------------------------------------ */
/*  Resolve project                                                   */

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Sign in at the Mastra Studio URL and create an organization, then re-run deploy
  2. If the org exists, check that your MASTRA_API_TOKEN belongs to an account with org membership
  3. Verify you are authenticating against the intended Studio instance (correct base URL / token pair)
  4. Set MASTRA_ORG_ID explicitly along with MASTRA_API_TOKEN for headless runs once the org exists

Example fix

// before
export MASTRA_API_TOKEN=tok_xxx
mastra studio deploy --yes
// Error: You have no organizations. Please create one at https://studio.mastra.ai
// after (create org 'Acme' in Studio UI first)
export MASTRA_API_TOKEN=tok_xxx
export MASTRA_ORG_ID=org_acme
export MASTRA_PROJECT_ID=prj_xxx
mastra studio deploy --yes
Defensive patterns

Strategy: validation

Validate before calling

const orgs = await fetchOrgs(token);
if (orgs.length === 0) {
  throw new Error(`No organizations for this token. Create one at ${STUDIO_URL} or use a token with org access.`);
}

Type guard

function hasOrganizations(orgs: Org[]): orgs is [Org, ...Org[]] {
  return orgs.length > 0;
}

Try / catch

try {
  await studioDeploy();
} catch (e) {
  if (e instanceof Error && e.message.includes('You have no organizations')) {
    console.error(`Create an organization at ${STUDIO_URL}, then retry.`);
    process.exitCode = 2;
  } else throw e;
}

Prevention

When it happens

Trigger: Calling `mastra studio deploy` with an API token / login belonging to a brand-new account that has never created an organization; an org previously existing but deleted, or the token lacking access to any org.

Common situations: Fresh sign-ups automating deploys before creating an org in the Studio UI; service tokens scoped to nothing; org removed by an admin while CI still holds old credentials.

Related errors


AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30). Data as JSON: /api/errors/4197e38a4adaff2a. Report an issue: GitHub.