{"record":{"id":"46dba35a8f32b474","repo":"mastra-ai/mastra","slug":"mastra-org-id-and-mastra-project-id-are-required-w","errorCode":null,"errorMessage":"MASTRA_ORG_ID and MASTRA_PROJECT_ID are required when MASTRA_API_TOKEN is set","messagePattern":"MASTRA_ORG_ID and MASTRA_PROJECT_ID are required when MASTRA_API_TOKEN is set","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/cli/src/commands/deploy/index.ts","lineNumber":577,"sourceCode":"      hasEnvFile: Boolean(opts.envFile),\n      hasConfig: Boolean(opts.config),\n      debug: Boolean(opts.debug),\n      headless: Boolean(process.env.MASTRA_API_TOKEN),\n      targetApi: bucketApiHost(MASTRA_PLATFORM_API_URL),\n    },\n    execution: () => runUnifiedDeploy(dir, opts),\n    origin: process.env.MASTRA_ANALYTICS_ORIGIN as CLI_ORIGIN | undefined,\n  });\n}\n\nasync function runUnifiedDeploy(dir: string | undefined, opts: DeployOptions) {\n  const targetDir = resolve(dir || process.cwd());\n  await assertDeployDir(dir, targetDir);\n  loadDeployEnvFromDotenv(targetDir);\n\n  const isHeadless = Boolean(process.env.MASTRA_API_TOKEN);\n  if (isHeadless && (!process.env.MASTRA_ORG_ID || !process.env.MASTRA_PROJECT_ID)) {\n    throw new Error('MASTRA_ORG_ID and MASTRA_PROJECT_ID are required when MASTRA_API_TOKEN is set');\n  }\n\n  const autoAccept = opts.yes ?? isHeadless;\n  const skipPreflight = opts.skipPreflight || process.env.MASTRA_SKIP_PREFLIGHT === '1';\n  const envName = opts.env || 'production';\n\n  p.intro(`${pc.bold('mastra deploy')} → ${pc.cyan(envName)}`);\n\n  // Gather context\n  const packageName = getPackageName(targetDir);\n  const gitBranch = getGitBranch(targetDir);\n  const mastraVersion = getMastraVersion(targetDir);\n\n  // Step 1: Auth\n  const token = await getToken();\n\n  // Step 2: Load existing project config\n  const projectConfig = await loadProjectConfig(targetDir, opts.config);","sourceCodeStart":559,"sourceCodeEnd":595,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/cli/src/commands/deploy/index.ts#L559-L595","documentation":"Thrown by runUnifiedDeploy during headless-mode validation. When MASTRA_API_TOKEN is set, the CLI assumes a non-interactive CI/headless deploy, which requires MASTRA_ORG_ID and MASTRA_PROJECT_ID to identify the target. Without them the CLI cannot determine where to deploy, so it fails fast before any interactive prompting.","triggerScenarios":"process.env.MASTRA_API_TOKEN is truthy AND (MASTRA_ORG_ID is unset/empty OR MASTRA_PROJECT_ID is unset/empty) when running `mastra deploy`. This happens after loadDeployEnvFromDotenv has loaded the target dir's .env, so missing values in the environment or dotenv file both trigger it.","commonSituations":"CI pipeline exports the API token but forgets org/project IDs; .env file has MASTRA_API_TOKEN but not the org/project variables; typos in variable names (e.g. MASTRA_ORGANIZATION_ID); running locally with a token set in shell profile but no project context.","solutions":["Set MASTRA_ORG_ID and MASTRA_PROJECT_ID in the environment (or in the target directory's .env) alongside MASTRA_API_TOKEN.","Copy the org ID and project ID from the Mastra dashboard and export them in your CI secrets.","If you intended an interactive deploy, unset MASTRA_API_TOKEN so the CLI can prompt for the missing values.","Check for typos — the CLI expects exactly MASTRA_ORG_ID and MASTRA_PROJECT_ID (loaded from dotenv too)."],"exampleFix":"// CI before (fails)\nexport MASTRA_API_TOKEN=sk-...\nmastra deploy\n// after\nexport MASTRA_API_TOKEN=sk-...\nexport MASTRA_ORG_ID=org_abc123\nexport MASTRA_PROJECT_ID=prj_xyz789\nmastra deploy","handlingStrategy":"validation","validationCode":"if (process.env.MASTRA_API_TOKEN && !(process.env.MASTRA_ORG_ID && process.env.MASTRA_PROJECT_ID)) {\n  throw new Error('Headless deploy requires MASTRA_API_TOKEN + MASTRA_ORG_ID + MASTRA_PROJECT_ID');\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Define MASTRA_ORG_ID and MASTRA_PROJECT_ID as CI secrets alongside MASTRA_API_TOKEN.","Keep all three variables together in your project's .env file.","Use the exact variable names — no ORGANIZATION or PROJECT aliases.","Unset MASTRA_API_TOKEN for local interactive deploys."],"tags":["environment","configuration","cli","ci"],"backgroundTag":"missing-env-var","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}