mem0ai/mem0 · error · Error

projectId must be set to access webhooks

Error message

projectId must be set to access webhooks

What it means

Thrown by MemoryClient.getWebhooks() when no project ID is available to build the /api/v1/webhooks/projects/{projectId}/ URL. The hosted client resolves projectId from an async identity ping (_awaitIdentity); if the caller did not pass data.projectId and the resolved identity has no project, the SDK refuses to guess. This is a precondition failure before any HTTP request is made.

Source

Thrown at mem0-ts/src/client/mem0.ts:677

    const response = await this._fetchWithErrorHandling(
      `${this.host}/api/v1/orgs/organizations/${this.organizationId}/projects/${this.projectId}/`,
      {
        method: "PATCH",
        headers: this.headers,
        body: JSON.stringify(camelToSnakeKeys(prompts)),
      },
    );
    return response;
  }

  // WebHooks
  async getWebhooks(data?: { projectId?: string }): Promise<Array<Webhook>> {
    this._captureEvent("get_webhooks", []);
    if (!data?.projectId) await this._awaitIdentity();
    const project_id = data?.projectId || this.projectId;
    if (!project_id) {
      throw new Error("projectId must be set to access webhooks");
    }
    const response = await this._fetchWithErrorHandling(
      `${this.host}/api/v1/webhooks/projects/${project_id}/`,
      {
        headers: this.headers,
      },
    );
    return response;
  }

  async createWebhook(webhook: WebhookCreatePayload): Promise<Webhook> {
    this._captureEvent("create_webhook", []);
    await this._awaitIdentity();
    if (!this.projectId) {
      throw new Error("projectId must be set to create a webhook");
    }
    const body = {
      name: webhook.name,

View on GitHub (pinned to 001c235229)

Solutions

  1. Pass the project explicitly: await client.getWebhooks({ projectId: 'proj_...' }) — an explicit projectId skips the identity wait entirely
  2. Verify your API key belongs to a project in the Mem0 dashboard (Projects -> select -> API keys) and regenerate the key if the project was created after the key
  3. Confirm the ping endpoint is reachable and returns a payload with projectId (check network tab / client.getOrgsProjects())
  4. If constructing MemoryClient with an orgId/projectId in options, verify those values are correct and non-empty

Example fix

// before
const webhooks = await client.getWebhooks();

// after
const webhooks = await client.getWebhooks({ projectId: 'proj_abc123' });
Defensive patterns

Strategy: validation

Validate before calling

const pid = explicitProjectId ?? (await client.getOrgsProjects())?.[0]?.id;
if (!pid) throw new Error('No Mem0 project available for this API key');
const webhooks = await client.getWebhooks({ projectId: String(pid) });

Type guard

const hasProjectId = (d?: { projectId?: string }): d is { projectId: string } =>
  typeof d?.projectId === 'string' && d.projectId.length > 0;

Try / catch

try {
  const webhooks = await client.getWebhooks({ projectId });
} catch (e) {
  if (e instanceof Error && e.message.includes('projectId must be set')) {
    // identity/API-key problem, not transient: fix key scope and fail loudly
    throw new Error('Mem0 API key has no project scope');
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling client.getWebhooks() with no argument while the API key's identity has no project attached (personal-key-only account, key scoped to an org without a default project, or the identity ping failed/returned null projectId). Also triggered by passing { projectId: "" } (empty string is falsy).

Common situations: Using a legacy Mem0 API key created before projects existed; running in CI where the identity endpoint is blocked so projectId never populates; migrating from an older SDK that inferred the project differently; account with multiple projects but no default.

Related errors


AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15). Data as JSON: /api/errors/ccffff88f9d0da73. Report an issue: GitHub.