mem0ai/mem0 · error · Error

organizationId and projectId must be set to access…

Error message

organizationId and projectId must be set to access instructions or categories

What it means

getProject() (which serves project instructions/categories) builds a URL from this.organizationId and this.projectId, which are only populated after the initialization ping returns them for your API key. If either is unset — ping hasn't resolved, or the key has no project context — the client throws instead of issuing a request to a malformed URL like /api/v1/orgs/organizations/null/projects/null/.

Solutions

  1. Use an API key tied to an organization and project in the Mem0 platform (check the dashboard for your org/project).
  2. Await a trivial client call first (or the client's initialization promise if exposed) so the ping has completed before getProject().
  3. If self-hosting without orgs/projects, don't use getProject — that route exists on the platform API surface only.

Example fix

// before
const client = new MemoryClient({ apiKey });
await client.getProject({ fields: ['instructions'] }); // org/project still null

// after
const client = new MemoryClient({ apiKey: PLATFORM_ORG_KEY });
await client.add(messages, { filters: { user_id: 'warmup' } }); // ping completes, identity set
await client.getProject({ fields: ['instructions'] });
Defensive patterns

Strategy: validation

Validate before calling

// Warm up identity before project calls: any first call awaits the ping
await client.users().catch(() => {});

// If your key has no org/project, getProject cannot work — verify via a raw ping:
const ping = await fetch(`${host}/v1/ping/`, { headers: { Authorization: `Token ${apiKey}` } }).then(r => r.json());
if (!ping.orgId || !ping.projectId) throw new Error('API key has no org/project context — use a platform key');

Type guard

const hasProjectIdentity = (ping: unknown): ping is { orgId: string; projectId: string } =>
  isJsonObject(ping) && typeof ping.orgId === 'string' && typeof ping.projectId === 'string';

Try / catch

try {
  await client.getProject({ fields: ['instructions'] });
} catch (e) {
  if ((e as Error).message.includes('organizationId and projectId must be set')) {
    throw new Error('getProject needs an org-scoped API key — check MEM0_API_KEY scope'); // config error, not transient
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling getProject() before the async ping completes (this._awaitIdentity() resolved but the key returned no orgId/projectId), using an API key that belongs to no organization/project, or calling from a context where initialization failed silently.

Common situations: Personal/free-tier keys with no org; calling getProject immediately after construction before identity resolves; hosted key used where a platform org key is required.

Related errors


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

Appendix: source

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

    const response = await this._fetchWithErrorHandling(
      `${this.host}/v1/batch/`,
      {
        method: "DELETE",
        headers: this.headers,
        body: JSON.stringify({ memories: memoriesBody }),
      },
    );
    return response;
  }

  async getProject(options: ProjectOptions): Promise<ProjectResponse> {
    const payloadKeys = Object.keys(options || {});
    this._captureEvent("get_project", [payloadKeys]);
    const { fields } = options;
    await this._awaitIdentity();

    if (!(this.organizationId && this.projectId)) {
      throw new Error(
        "organizationId and projectId must be set to access instructions or categories",
      );
    }

    const params = new URLSearchParams();
    fields?.forEach((field) => params.append("fields", camelToSnake(field)));

    const response = await this._fetchWithErrorHandling(
      `${this.host}/api/v1/orgs/organizations/${this.organizationId}/projects/${this.projectId}/?${params.toString()}`,
      {
        headers: this.headers,
      },
    );
    return response;
  }

  async updateProject(
    prompts: PromptUpdatePayload,

View on GitHub (pinned to 001c235229)