---
title: "Deploy Mem0"
description: "Self-hosted AI agent memory: REST API, dashboard and pgvector"
category: "AI/ML"
url: https://railway.com/deploy/mem0-2
---

# Deploy Mem0

Self-hosted AI agent memory: REST API, dashboard and pgvector

**[Deploy Mem0 on Railway](https://railway.com/template/mem0-2)**

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

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

## Template content

### mem0-api

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

### 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

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

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

### mem0-dashboard

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

## Documentation

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

Mem0 is an Apache-2.0 memory layer that extracts durable facts from conversations with an LLM, stores them as embeddings, and returns relevant ones per user, agent, or run.

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

This template runs Mem0 v2.2.1 (Sep 25 2026) built from the pinned upstream commit into amd64 images and deployed by digest; the official server image is arm64-only and from Sept 2025. Unlike other Railway Mem0 templates, it boots with zero input and needs no OpenAI key at deploy.

## Why Deploy Mem0, the Mem0 Platform alternative on Railway (Railway Free Trial)

Self-hosting gives you the same core extraction and retrieval without per-request pricing, full data control, and private-network access from other Railway services.

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 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 self hosting

| Provider | Managed Postgres with pgvector | Deploy effort | Scaling | Backups |
|---|---|---|---|---|
| DigitalOcean | No, you run your own Postgres droplet or managed DB with extension setup | Manual Docker Compose, you handle Caddy or Nginx | Vertical resize only, manual | Manual snapshots |
| AWS | RDS supports pgvector but you configure security groups and VPC | ECS or EC2 with load balancer and IAM roles | Auto scaling groups but lots of setup | RDS automated snapshots |
| Hetzner | No managed Postgres with pgvector, you install Postgres and extension | Bare metal or cloud VM, manual everything | Manual, no built-in autoscaling | Manual snapshots or Barman |
| Railway | Built-in Postgres with pgvector enabled automatically | One click deploy, Caddy proxy already set | Scale each service horizontally or vertically from dashboard | Volume backups from the dashboard |

## Common Use Cases for hosted Mem0

Customer support bots recall a user's plan, device, and previous tickets across sessions. Personal assistants store preferences, allergies, and recurring tasks. Multi-agent systems share a memory namespace per user_id or agent_id, so one agent can recall what another learned.

## Dependencies for Mem0 Docker hosted on Railway

Four services: Caddy proxy, FastAPI API, Next.js dashboard, and Railway Postgres with pgvector. API and dashboard are private, exposed through one domain. No other external service is required at deploy time; the stack boots healthy even with empty OpenAI and embedder keys.

### Deployment Dependencies for Managed Mem0 Service (AI Memory)

Generated secrets: JWT_SECRET (dashboard sessions), ADMIN_API_KEY (server-wide admin key sent as X-API-Key header), POSTGRES_PASSWORD.

### Implementation Details for Mem0 (Built from the Mem0 v2.2.1 release)

Caddy 2.11.7 runs on port 8080 with health check /healthz. It routes API paths like /memories, /search, /auth, /api-keys, and /docs to mem0-api; everything else goes to the dashboard.

## How does Mem0 compare against other AI memory platforms

### Mem0 vs Zep

- **Memory model:** Mem0 stores extracted facts as vector embeddings with user_id, agent_id, or run_id scoping. Zep adds temporal knowledge graphs and timeline-based memory.
- **Open source:** Mem0 is Apache-2.0. Zep's Graphiti is open source, but Zep Cloud is a commercial service.
- **Self-host complexity:** Mem0's server and dashboard are two containers plus Postgres. Zep requires a temporal graph store and more moving parts.
- **Graph queries:** This template runs vector memory on Postgres only, with no graph database. Zep is built around relationships that change over time.

### Mem0 vs Letta

- **Memory layer vs agent runtime:** Mem0 is a separate memory API you call from any agent. Letta is a stateful agent server where memory lives inside the runtime (formerly MemGPT).
- **License:** Both are Apache 2.0.
- **Integration path:** You add Mem0 to your existing FastAPI or LangChain app. You replace or build your agent inside Letta.
- **Persistence model:** Mem0 stores extracted facts in Postgres. Letta stores agent state and memory blocks in its own store, often Postgres or SQLite.

### Mem0 vs LangMem

- **Form factor:** Mem0 is a standalone service with REST API and dashboard. LangMem is a Python library for adding memory to LangGraph apps.
- **Extraction logic:** Mem0 uses an LLM to extract durable facts and deduplicate them. LangMem gives you building blocks like profile, collection, and semantic memory managers.
- **Deployment:** Mem0 runs as a separate container reachable over HTTP. LangMem runs inside your existing Python process.
- **UI:** Mem0 ships a dashboard for managing providers, API keys, and memory settings. LangMem has no built-in UI.

### Mem0 vs a plain vector database

- **Fact extraction:** A vector DB stores raw text or chunks. Mem0 uses an LLM to extract concise facts, merge updates, and resolve contradictions.
- **Deduplication:** Mem0 updates existing memories instead of appending duplicates. You write that dedup logic yourself with pgvector or Qdrant.
- **Scoping:** Mem0 has first-class user_id, agent_id, and run_id filters. A plain vector DB requires you to design and index metadata yourself.
- **API surface:** Mem0 gives you /memories and /search endpoints out of the box. A vector DB gives you only low-level insert and query operations.

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

After deploy, open the domain right away. The first account created in the setup wizard becomes admin, and registration then closes. Log in to the dashboard and create per-app API keys under API Keys; those keys use the m0sk_ prefix.

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

The upstream Mem0 repository includes the server and dashboard with Docker Compose. You can run the same stack on any VPS with Docker installed.

### Clone the Repository

Run `git clone https://github.com/mem0ai/mem0` and then `cd mem0`, `git checkout v2.2.1`, and `cd server`. The dashboard lives under server/dashboard.

### Install Dependencies

Use the provided Docker Compose file. Install Docker and Docker Compose on your VPS. On amd64 hosts, build the images locally with `docker compose build`, since the official server image is arm64-only.

### Configure Environment Variables

Copy the example environment file with `cp .env.example .env`. Fill in the Postgres settings, OPENAI_API_KEY to your OpenAI key, and optionally OPENAI_BASE_URL for an OpenAI-compatible endpoint. Set JWT_SECRET and ADMIN_API_KEY to random strings.

### Start the Mem0 Application

Run `docker compose up -d` to start the API, dashboard, and Postgres. The API waits for Postgres, runs migrations, and listens on port 8000. The dashboard listens on port 3000. Use a reverse proxy like Caddy or Nginx to expose both on one domain. Upstream docs are at docs.mem0.ai/open-source.

## Official Pricing of Mem0 (Mem0 pricing)

The commercial Mem0 Platform at mem0.ai/pricing has four tiers. Hobby is free and includes 10,000 add requests and 1,000 retrieval requests per month. Starter costs 19 USD per month, Pro costs 249 USD per month, and Enterprise is custom. Self hosting has no request caps; you pay only for Railway resources and model tokens.

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

The cloud platform adds hosted infrastructure, graph memory, analytics, and higher request limits. Self-hosting gives you the same core extraction and retrieval, but you run Postgres, the API, and the dashboard yourself. You pay only for Railway resources and your LLM and embedding API usage.

### Monthly cost of self hosting Mem0 on Railway

Cost follows usage. The Caddy proxy and dashboard are light, the API mostly waits on your model provider, and Postgres grows with stored memories. Heavier memory volumes or many concurrent agents will push the Postgres and API services higher.

### System Requirements for Hosting Mem0 on a VPS

Upstream does not publish minimums. Fact extraction and embeddings run at your LLM provider, so the containers stay small. Disk holds the Postgres data and the SQLite history file, and grows with memory volume. Size up Postgres first as memories accumulate.

## Frequently Asked Questions (FAQs)

### Do I need an OpenAI API key at deploy time?

No. The stack boots healthy with empty OPENAI_API_KEY. Memory endpoints return provider_not_configured until you set a key on mem0-api or choose a provider on the dashboard Configuration page.

### Can I use Anthropic or Gemini instead of OpenAI?

Yes. Anthropic and Gemini LLMs are bundled in the API. Embeddings can use OpenAI or Gemini. For other providers, set OPENAI_BASE_URL to any OpenAI-compatible endpoint like OpenRouter or LiteLLM.

### How do I secure the dashboard and API?

The first account created in the setup wizard becomes admin and registration closes. The dashboard uses JWT sessions. For server-to-server calls, use the ADMIN_API_KEY in the X-API-Key header or create per-app API keys with the m0sk_ prefix.

### How do I call Mem0 from another Railway service?

Use the private network. Point your service at mem0-api on port 8000. No public domain or CORS setup is needed. The public Caddy proxy only exposes the domain, but the API is reachable directly inside the same Railway project.

### Can I change the embedding model later?

Yes, but be careful. Changing the embedding model changes vector dimensions. If the new model has a different dimension, you need a new Postgres collection name. Set POSTGRES_COLLECTION_NAME to a new value and restart the API.


## Similar templates

- [Chat Chat](https://railway.com/deploy/-WWW5r) — Chat Chat, your own unified chat and search to AI platform.
- [stella](https://railway.com/deploy/stella) — Self-host stella with web, API, Postgres, Redis, and object storage.
- [Hermes Agent | OpenClaw Alternative with Dashboard](https://railway.com/deploy/hermes-agent-or-openclaw-alternative-wit) — Self-Hosted Hermes AI Agent for Telegram, Discord & Slack

Open this page in a browser: https://railway.com/deploy/mem0-2
