mastra-ai/mastra · error · PlatformApiError

Failed to create project — ${await extractError(res)}

Error message

Failed to create project — ${await extractError(res)}

What it means

createServerProject POSTs to /v1/server/projects with `{ name, region, factoryEnabled: true }`. Any non-ok response is converted into a PlatformApiError carrying the upstream HTTP status and the server-provided error body (via extractError) prefixed with 'Failed to create project —'.

Source

Thrown at mastracode/mastra-factory/src/platform.ts:84

/** POST /v1/server/projects — create a server project (Railway-provisioned). */
export async function createServerProject({
  token,
  orgId,
  name,
  region,
}: {
  token: string;
  orgId: string;
  name: string;
  region: ProjectRegion;
}): Promise<PlatformProject> {
  const res = await platformFetch(`${MASTRA_PLATFORM_API_URL}/v1/server/projects`, {
    method: 'POST',
    headers: { ...authHeaders(token, orgId), 'Content-Type': 'application/json' },
    body: JSON.stringify({ name, region, factoryEnabled: true }),
  });
  if (!res.ok) {
    throw new PlatformApiError(res.status, `Failed to create project — ${await extractError(res)}`);
  }
  const body = (await res.json()) as CreateProjectResponse;
  return body.project;
}

/**
 * POST /v1/auth/tokens — mint an `sk_` WorkOS org API key.
 * Returns the plaintext secret; the platform never returns it again.
 */
export async function mintOrgApiKey({
  token,
  orgId,
  keyName,
}: {
  token: string;
  orgId: string;
  keyName: string;
}): Promise<string> {

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Read the status and message after the em-dash in the error; fix the specific cause (e.g. choose another name on 409, re-login on 401).
  2. Verify the region id against the platform's supported region list.
  3. Re-authenticate (`mastra auth login`) if the token is stale, and confirm your org role allows project creation.
  4. Retry after a short wait if the status is 5xx (platform-side issue).

Example fix

// before
await createServerProject({ token, orgId, name: 'my-factory', region: 'us-east-1' });
// after
const REGIONS = ['us-east-1', 'us-west-2']; // confirmed against platform docs
if (!REGIONS.includes(region)) throw new Error(`Unsupported region: ${region}`);
await createServerProject({ token, orgId, name: 'my-factory', region });
Defensive patterns

Strategy: try-catch

Validate before calling

if (!/^[a-zA-Z0-9][a-zA-Z0-9-_]*$/.test(projectName)) throw new Error('Invalid project name');
if (!supportedRegions.includes(region)) throw new Error(`Unsupported region: ${region}`);
const existing = await listServerProjects({ token, orgId });
if (existing.some(p => p.name === projectName)) throw new Error(`Project name '${projectName}' already in use`);

Type guard

function isPlatformApiError(e) { return e instanceof PlatformApiError; }

Try / catch

try {
  const project = await createServerProject({ token, orgId, name, region });
} catch (err) {
  if (err instanceof PlatformApiError && err.status === 409) {
    name = `${name}-${Date.now()}`; // retry with unique name
  } else if (err instanceof PlatformApiError && err.status === 401) {
    await refreshAuth();
  } else throw err;
}

Prevention

When it happens

Trigger: POST /v1/server/projects returns 4xx/5xx: e.g. 401/403 for bad/expired token or missing role, 409 for a duplicate project name, 400 for an invalid region or name, 500 for a platform-side outage.

Common situations: Expired auth token after a long session; project name already used in the org; unsupported or typo'd region id; org admin permissions missing; platform maintenance window returning 502/503.

Related errors


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