---
title: "Deploy Mem0 REST API"
description: "Add and search agent memories over plain HTTP"
category: "AI/ML"
url: https://railway.com/deploy/deploy-mem0-rest-api-memory-server
---

# Deploy Mem0 REST API

Add and search agent memories over plain HTTP

**[Deploy Mem0 REST API on Railway](https://railway.com/template/deploy-mem0-rest-api-memory-server)**

Machine-readable deploy manifest (JSON, validated by TemplateCI): https://railway.com/deploy/deploy-mem0-rest-api-memory-server/manifest.json

- **Creator:** onepush
- **Category:** AI/ML

## Template content

### mem0-dashboard

- **Image:** ghcr.io/onepush-dev/mem0-dashboard:v2.2.1@sha256:9e654f2351b8177296146aab1ba28aa27159b2f54f012762a57c8d59d0c58e82
- **Health check:** /api/health

### Postgres https://devicons.railway.app/i/postgresql.svg

- **Image:** ghcr.io/railwayapp-templates/postgres-ssl:18

### mem0

- **Image:** caddy:2.11.7-alpine@sha256:d8542f48d34a9cf4e4c11a478865229840e87e4c96ea3f439101f31a5d35f75f
- **Start command:** `sh -c 'printf "%s\n" "$CADDYFILE" > /etc/caddy/Caddyfile && exec caddy run --config /etc/caddy/Caddyfile --adapter caddyfile'`
- **Health check:** /healthz
- **Public domain:** Yes

### mem0-api

- **Image:** ghcr.io/onepush-dev/mem0-api:v2.2.1@sha256:b43ca243fffdbb8112992b87eb32da39a2e28de2491198a9f72827fe24f8ff91
- **Health check:** /docs

## Documentation

# Deploy and Host self hosted Mem0 REST API (Open-Source Agent Memory API) on Railway

This template runs the Mem0 v2.2.1 REST server, its dashboard and Postgres with pgvector behind one Caddy proxy. You call it over plain HTTP from any language with an X-API-Key header.

## About Hosting Mem0 REST API open-source software on Railway (self hosted Mem0 REST API template)

Your memories stay in your own Postgres 18 with pgvector, not a vendor cloud, and the history DB sits on the /app/history volume. Railway handles private networking, volumes, and TLS, so you only manage the m0sk_ keys.

## Why Deploy Mem0 REST API, the Zep alternative on Railway (Railway Free Trial)

Self-hosting Mem0 keeps memories and API keys in your own Postgres, and the Apache-2.0 server costs nothing beyond compute. Try it on the $5 Railway trial and cancel if it does not fit.

Railway is a singular platform to deploy your infrastructure stack. Railway will host your infrastructure so you don't have to deal with configuration, while allowing you to vertically and horizontally scale it.

By deploying Mem0 REST API on Railway, you are one step closer to supporting a complete full-stack application with minimal burden. Host your servers, databases, AI agents, and more on Railway.

### Railway vs Other Hosting Providers and VPS for Mem0 REST API self hosting

Mem0 is a small stack, but you still need a Postgres with pgvector and a private network path to mem0-api:8000.

| Provider | What You Get with Railway | What You Get with the Other Provider |
| --- | --- | --- |
| DigitalOcean | Four services, pgvector Postgres and private networking wired in one deploy | A Droplet plus a Managed Postgres, with the compose file, proxy and TLS on you |
| AWS | Same-origin Caddy gateway and private mem0-api calls from the start | ECS or EC2, an RDS instance and a load balancer you configure and pay for separately |
| Hetzner | Digest-pinned images with volume and secret handling built in | A VPS where you install Docker, Caddy and Postgres and patch them yourself |

The API surface stays the same on all three; the difference is how much wiring you own.

## Common Use Cases for hosted Mem0 REST API

- **Go or Java chat backends:** after each turn, POST /memories with the message pair and a user_id, then run POST /search before the next prompt to pull durable facts back. No SDK, just an HTTP client.
- **PHP apps storing preferences:** a Laravel controller writes "prefers dark mode, ships to Berlin" with one POST /memories call and reads it back on login with GET /memories?user_id=..., keeping the m0sk_ key in server config.
- **n8n and workflow tools:** the HTTP Request node hits /memories and /search directly, so support-ticket bots can remember past tickets without custom code.
- **Private service-to-service calls:** other Railway services in the same project skip Caddy and call http://mem0-api:8000 for configure, entities and request-log endpoints that the public gateway does not expose.
- **Nightly cleanup scripts:** a cron job sends DELETE /memories with a user_id filter (or DELETE /entities/user/ID) to drop stale profiles before they cost you search relevance.

## Dependencies for Mem0 REST API Docker hosted on Railway

Four services come up and only one is public. Postgres 18 with pgvector holds memories and app tables.

### Deployment Dependencies for Managed Mem0 REST API Service (Agent Memory API)

You need a Railway project, Postgres with pgvector, and an OpenAI key or compatible base URL. Railway generates JWT_SECRET, ADMIN_API_KEY and POSTGRES_PASSWORD.

### Implementation Details for Mem0 REST API (Using Mem0 official docker image)

Images are pinned to ghcr.io/onepush-dev/mem0-api:v2.2.1 and mem0-dashboard:v2.2.1. Run one replica.

## How does Mem0 REST API compare against other agent memory APIs

### Mem0 vs Zep (Zep Alternative)

- **Memory model:** Mem0 extracts durable facts into embeddings keyed by user_id or agent_id; Zep builds a temporal knowledge graph that tracks how facts change.
- **Interface:** Mem0 is plain HTTP with an X-API-Key header and no /v1 prefix; Zep's Graphiti engine is Python-first.
- **Where Zep wins:** reasoning about contradictions and what changed over time. Mem0 v2 dropped the graph store, so you get flat vector recall.
- **Ops:** four Railway services and pgvector cover Mem0; Zep self hosting means running Graphiti plus its own datastore.

### Mem0 vs Letta (Letta Alternative)

- **Scope:** Mem0 is memory you call from any language; Letta is a stateful agent server (formerly MemGPT) that owns the whole loop.
- **Fit:** keep your Go or PHP backend and add POST /search; Letta wants agent logic inside its runtime.
- **Where Letta wins:** built-in agent state and self-editing memory blocks, with no separate extraction step to wire up.

### Mem0 vs LangMem (LangMem Alternative)

- **Language reach:** Mem0 is HTTP with an m0sk_ key, so Go, Java or PHP clients work; LangMem is a LangChain library for LangGraph apps.
- **Ops:** Mem0 ships Postgres, pgvector and a dashboard; with LangMem you pick and run the store yourself.
- **Where LangMem wins:** tighter hooks into LangGraph state and one less service and key to operate.

### Mem0 vs Supermemory (Supermemory Alternative)

- **Output shape:** Mem0 returns extracted facts plus per-memory history at /memories/MEMORY_ID/history; Supermemory pitches a managed memory API with connectors.
- **Data control:** self hosted Mem0 keeps memories in your own Postgres, while hosted-first products hold the records for you.
- **Where Supermemory wins:** managed ingestion and integrations, if running a server and database is work you would rather skip.

## How to use Mem0 REST API (the OSS AI memory layer)?

1. Open your Railway domain and finish /setup. The first account becomes admin, then registration closes.
2. Set OPENAI_API_KEY (or OPENAI_BASE_URL) on mem0-api and redeploy. Without it, memory calls return provider_not_configured.
3. Create a per-app key under API Keys in the dashboard. The m0sk_ key shows once, so keep it server-side.

```bash
curl -X POST https://your-domain/memories \
 -H "X-API-Key: m0sk_..." -H "Content-Type: application/json" \
 -d '{"messages":[{"role":"user","content":"I run Go and PHP"}],"user_id":"alice"}'
```

4. Search with `POST /search`, sending a query plus user_id.
5. List with `GET /memories?user_id=alice`; the full schema lives at /docs.

## How to self host Mem0 REST API on other VPS Services (Mem0 self hosting guide)

A plain VPS run needs Postgres with pgvector, the mem0-api server, and a reverse proxy in front of both. The upstream repo ships the server and the dashboard together.

### Clone the Repository

```bash
git clone https://github.com/mem0ai/mem0.git
cd mem0/server
```

### Install Dependencies

Docker with Compose. The server/docker-compose.yaml builds the API and dashboard and runs pgvector Postgres 17; it is a dev setup with --reload, so harden it for production.

### Configure Environment Variables

Run cp .env.example .env, then set JWT_SECRET, POSTGRES_PASSWORD and OPENAI_API_KEY. The API boots without the key, but memory calls return provider_not_configured.

### Start the Mem0 REST API Application

```bash
docker compose up -d
curl -s http://localhost:8888/docs
```

The API listens on host port 8888 and the dashboard on 3000; put a TLS proxy in front and run one replica.

Railway already wires the Caddy gateway, the pgvector database, the history volume, and private networking between services, so you skip the compose file entirely.

## Official Pricing of Mem0 REST API (Mem0 pricing)

The server itself is Apache-2.0 and free.

Mem0's cloud has paid tiers: Hobby is free with 10,000 adds and 1,000 retrievals a month, Starter is 19 USD/mo for 50,000 adds and 5,000 retrievals, and Pro is 249 USD/mo for 500,000 adds and 50,000 retrievals.

Self hosting drops the request fees: you pay Railway usage, roughly 10 to 20 USD/mo at light load, plus LLM and embedding tokens for every add and search. Enterprise pricing is custom.

## Mem0 REST API cloud vs self hosted comparison (Pricing, features, costs, and more)

The API surface is identical either way: same endpoints, same X-API-Key header, same JSON bodies. What changes is who runs Postgres with pgvector, who holds the provider key, and who pays per add and per search.

### Monthly cost of self hosting Mem0 REST API on Railway

Expect roughly $10-20 per month for the four small services plus Postgres at light use, and the $5 trial covers the first stretch. The software itself is Apache-2.0 and free.

### System Requirements for Hosting Mem0 REST API on a VPS

A small box with a couple of vCPU and around 2 GB of RAM handles light traffic, provided you run Postgres with pgvector and mount a persistent volume for the history DB at /app/history.

## Frequently Asked Questions (FAQs)

### Which auth header do I use?

`X-API-Key` with a per-app `m0sk_` key from the dashboard API Keys page. The generated ADMIN_API_KEY also travels as `X-API-Key`. Bearer tokens are only for dashboard sessions, so don't send them to /memories.

### Why do memory calls return provider_not_configured?

Because no LLM or embedder is set. The stack boots healthy without a key; only the memory calls fail.

### Is there a /v1 prefix?

No. Paths are `/memories`, `/search`, `/api-keys`, plain and unversioned, so a base URL of `https://your-domain` is all you need.

### Can other Railway services call it privately?

Yes. Other services in the same project reach `http://mem0-api:8000` over private networking and skip the public gateway entirely.

### Which endpoints are public?

The Caddy gateway (port 8080) exposes /memories, /search, /auth, /api-keys and /docs.

### How do I delete a user's memories?

Use `DELETE /memories` with a filter such as `{"user_id": "alice"}` for a bulk wipe, or `DELETE /memories/MEMORY_ID` for one record. Confirm with `GET /memories?user_id=alice` afterward.


## Similar templates

- [Chat Chat](https://railway.com/deploy/-WWW5r) — Chat Chat, your own unified chat and search to AI platform.
- [Möbius v0.1 Personal AI OS](https://railway.com/deploy/mobius-v01-personal-ai-os) — Self-hosted AI agent that builds and runs apps for you, with memory.
- [stella](https://railway.com/deploy/stella) — Self-host stella with web, API, Postgres, Redis, and object storage.

Open this page in a browser: https://railway.com/deploy/deploy-mem0-rest-api-memory-server
