mem0ai/mem0 · error · Error

Either memoryId or --all is required

Error message

Either memoryId or --all is required

What it means

The 401 branch of require_admin: the resolved user is None (no JWT, no API key, or admin/disabled auth that returned None) AND auth_type is neither 'admin_api_key' nor 'disabled' — meaning no credential was presented at all and no bootstrap fallback applies. Admin endpoints demand at least one of: an authenticated user, ADMIN_API_KEY, or AUTH_DISABLED.

Source

Thrown at cli/node/src/backend/platform.ts:338

			const params: Record<string, string> = { source: "CLI" };
			if (opts.userId) params.user_id = opts.userId;
			if (opts.agentId) params.agent_id = opts.agentId;
			if (opts.appId) params.app_id = opts.appId;
			if (opts.runId) params.run_id = opts.runId;
			return (await this._request("DELETE", "/v1/memories/", {
				params,
			})) as Record<string, unknown>;
		}
		if (memoryId) {
			const params: Record<string, string> = { source: "CLI" };
			if (opts.deleteLinked) params.delete_linked = "true";
			return (await this._request(
				"DELETE",
				`/v1/memories/${encodePathSegment(memoryId)}/`,
				{ params },
			)) as Record<string, unknown>;
		}
		throw new Error("Either memoryId or --all is required");
	}

	async deleteEntities(opts: EntityIds): Promise<Record<string, unknown>> {
		// v2 endpoint: DELETE /v2/entities/{entity_type}/{entity_id}/
		const typeMap: [string, string | undefined][] = [
			["user", opts.userId],
			["agent", opts.agentId],
			["app", opts.appId],
			["run", opts.runId],
		];
		const entities = typeMap.filter(([, v]) => v) as [string, string][];
		if (entities.length === 0) {
			throw new Error("At least one entity ID is required for deleteEntities.");
		}
		// Delete each provided entity via the v2 path-based endpoint. Key each
		// response by entity type so a multi-entity delete (e.g. --user-id and
		// --agent-id together) doesn't discard everything but the last result.
		const results: Record<string, unknown> = {};

View on GitHub (pinned to 001c235229)

Solutions

  1. Authenticate with a Bearer token belonging to an admin-role user (POST /auth/login with the admin registered at /setup).
  2. Or set ADMIN_API_KEY in the server env and send it as X-API-Key.
  3. If the access token expired, refresh it via POST /auth/refresh and retry.
  4. For local dev only, AUTH_DISABLED=true also satisfies this guard when a default user exists.

Example fix

# before
requests.delete(f"{BASE}/memories", params={"user_id": "alice"})  # 401

# after
tok = requests.post(f"{BASE}/auth/login", json={"email": ADMIN_EMAIL, "password": ADMIN_PW}).json()
requests.delete(f"{BASE}/memories", params={"user_id": "alice"},
                headers={"Authorization": f"Bearer {tok['access_token']}"})
Defensive patterns

Strategy: try-catch

Validate before calling

def ensure_admin_token(base: str, email: str, password: str) -> str:
    r = requests.post(f"{base}/auth/login", json={"email": email, "password": password})
    r.raise_for_status()
    return r.json()["access_token"]

Try / catch

if resp.status_code == 401:
    tok = ensure_admin_token(BASE, ADMIN_EMAIL, ADMIN_PASSWORD)
    resp = requests.request(method, url, headers={"Authorization": f"Bearer {tok}"}, ...)
    resp.raise_for_status()

Prevention

When it happens

Trigger: Calling admin-only endpoints (DELETE /memories, POST /reset, DELETE /api-keys/{id} is require_auth not this) with no Authorization/X-API-Key headers; sending an invalid JWT that verify_auth silently ignores, leaving user=None and auth_type='none'.

Common situations: Automation scripts hitting admin endpoints after a server upgrade added auth; expired JWT access token that the bearer branch treats as unauthenticated; reverse proxy stripping headers as in error 681.

Related errors


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