---
title: Self-hosting
description: Run OpenMemory yourself on Node.js with built-in SQLite, or on your own Cloudflare account with Workers and D1. Same API, same MCP server.
---

The service in [https://github.com/lalagias/openmemory](https://github.com/lalagias/openmemory) (License to be announced) runs in two ways from the same code in `apps/api`:

- **Node.js** with the built-in `node:sqlite` module. One process, one database file.
- **Cloudflare Workers + D1**, the way the hosted service runs.

Both serve the REST API under `/v1`, MCP at `/mcp`, the interactive reference at `/docs`, and the OpenAPI document at `/openapi.json`.

## Node.js

Requirements: Node.js 22.18 or newer (it runs the TypeScript source directly), and pnpm.

```bash
git clone https://github.com/lalagias/openmemory
cd openmemory
pnpm install
cd apps/api
node src/node.ts   # or: pnpm start
```

```text
openmemory listening on http://localhost:8787 (database: .../apps/api/data/openmemory.db)
```

Create a space against your server and connect clients to `http://localhost:8787/mcp`:

```bash
curl -s -X POST http://localhost:8787/v1/spaces -H 'content-type: application/json' -d '{"timezone":"Europe/Athens"}'
```

On Node:

- `PORT` sets the port (default `8787`) and `OM_DB_PATH` the SQLite file (default `apps/api/data/openmemory.db`). Migrations run automatically when the database opens.
- Maintenance (inactive-space cleanup, undo-history purge, nightly dreams, index optimize) runs in-process every hour.
- There is no server-side model, so spaces in `server` dream mode get housekeeping only. Use `client` mode (the default).
- Rate limits are kept in process memory.

## Cloudflare Workers + D1

From `apps/api`:

```bash
pnpm exec wrangler d1 create openmemory      # paste the database_id into wrangler.jsonc
pnpm db:migrate:remote                        # apply migrations to D1
pnpm run deploy                               # wrangler deploy
```

For local development: `pnpm db:migrate:local`, then `pnpm dev` (`wrangler dev`).

`wrangler.jsonc` already sets an hourly cron (`0 * * * *`) for maintenance. Optional bindings:

- **Workers AI** for `server` dream mode: uncomment `"ai": { "binding": "AI" }` and run `pnpm cf-typegen`. `OM_DREAM_MODEL` picks the model (default `@cf/meta/llama-3.3-70b-instruct-fp8-fast`). Without it, server-mode spaces get housekeeping only.
- **Rate limiting**: a Cloudflare Rate Limiting binding named `RATE_LIMITER` enforces the per-space limit across isolates (its own configured limit applies). Without it, the limit is kept per isolate, which makes it a soft limit.

## Configuration

Every limit can be overridden with an environment variable (Worker `vars` or `process.env`). Invalid values are ignored.

| Variable | Default |
| --- | --- |
| `OM_MAX_MEMORIES` | 5000 |
| `OM_MAX_RECORDS` | 2000 |
| `OM_MAX_OPEN_ACTIONS` | 500 |
| `OM_MAX_EVENTS` | 10000 |
| `OM_MAX_JOURNAL` | 800 |
| `OM_MAX_KV` | 1000 |
| `OM_MAX_BATCH_OPS` | 50 |
| `OM_MAX_BODY_BYTES` | 262144 (256 KB) |
| `OM_REQUESTS_PER_MINUTE` | 120 |
| `OM_SPACES_PER_HOUR_PER_IP` | 10 |
| `OM_INACTIVE_DAYS` | 90 |
| `OM_SCRATCH_DAYS` | 14 |
| `OM_DREAM_MAX_CHANGES` | 50 |
| `OM_DREAM_INTERVAL_HOURS` | 20 |

## Pointing clients at your server

Replace the hosted URLs in any guide:

| Hosted | Self-hosted |
| --- | --- |
| `https://api.openmemory.sh` | `http://localhost:8787` (or your Worker URL) |
| `https://mcp.openmemory.sh` | `http://localhost:8787/mcp` (or `https://<your-worker>/mcp`) |
