Deploy Mem0
Self-hosted Mem0: long-term memory API for AI agents, with a dashboard.
mem0-api
Just deployed
/app/history
mem0-dashboard
Just deployed
Just deployed
/var/lib/postgresql/data
Deploy and Host Mem0 on Railway
![]()
Mem0 is the open-source memory layer for AI agents, with 67,000+ GitHub stars. It extracts facts from conversations, stores them as searchable memories and returns the relevant ones on the next request, so your agents remember users across sessions. This template self-hosts the Mem0 REST API and its web dashboard on Railway, with Postgres as the vector store and history on a persistent volume. Mem0's hosted Pro plan is $249/month, and the $19 Starter plan caps you at 5,000 retrievals. Self-hosted Mem0 has no request caps and costs about $5–10/month plus your model API usage.
What This Template Deploys
| Service | Purpose |
|---|---|
| mem0-api | The Mem0 REST server (FastAPI) on port 8000 with a public HTTPS domain. Your agents and apps call it to add and search memories. |
| mem0-dashboard | The Next.js admin dashboard on port 3000: first-run setup, API keys, model configuration and the request log. |
| Postgres | Postgres 18 holding the vector store (memories table, pgvector) and a mem0_app database for users, keys and settings. |
| Persistent Volume | Mounted at /app/history on mem0-api. It keeps the memory change history across redeploys. |
Both app services are built from Mem0's own source at a release tag (v2.0.19), because upstream doesn't publish a current image. The API creates its database and runs migrations at boot. The dashboard talks to the API over the private network for server-side calls and over HTTPS from the browser.
About Hosting Mem0
Agents forget everything between sessions unless something stores what matters. Mem0 does that job: it runs an LLM over each conversation to pull out durable facts ("prefers dark mode", "allergic to peanuts"), embeds them, and lets you search them by user, agent or session. Running it yourself means a Python API server, a vector database, an embedding model, migrations, a dashboard, and HTTPS for the clients that call it.
On Railway, the API, dashboard and Postgres start together, connected through private networking and reference variables. HTTPS is automatic for both public services, a JWT secret is generated for dashboard sessions, CORS is preset to your dashboard domain, and telemetry is off. Memories stay in your own Postgres, never in a third-party memory service.
An LLM key is required. Mem0 uses a model for fact extraction (default gpt-5-mini) and embeddings (default text-embedding-3-small), so the deploy form asks for OPENAI_API_KEY. You can point OPENAI_BASE_URL at any OpenAI-compatible endpoint, or switch to Anthropic or Google in the dashboard.
Typical cost: ~$5–10/month on Railway for the three services, plus model usage, which is usually cents per thousand memories with small models. Mem0's hosted Starter plan is $19/month and Pro is $249/month.
Deploy Mem0 in Under 10 Minutes
- Click Deploy on Railway and paste your
OPENAI_API_KEY. Both services build from source (about 5–8 minutes). - Open the
mem0-dashboarddomain and complete the setup wizard to create your admin account. - Create an API key in the dashboard.
- Point your agent or app at the
mem0-apidomain with that key, then add memories after each conversation. - Search memories before each response, filtered by
user_id,agent_idorrun_id.
No vector database to run separately. No Python servers to babysit. No per-request bill.
Common Use Cases
- Self-hosted Mem0 Platform alternative. The same memory API with no add or retrieval caps.
- Personalised chatbots. Remember each user's preferences, history and context across sessions.
- Customer support agents. Recall past tickets and account details without stuffing whole transcripts into prompts.
- AI companions and tutors. Long-term memory of progress, goals and conversations per user.
- Multi-agent systems. Shared or per-agent memory scoped by
agent_id. - Lower token costs. Retrieve a few relevant memories instead of resending full chat history.
- Privacy-sensitive apps. Keep personal memories in your own database for compliance.
- Coding assistants. Remember project conventions, preferred libraries and past decisions for each developer.
- Sales and CRM agents. Recall each lead's needs, objections and last conversation before the next message goes out.
Configuration
| Variable | Required | Description |
|---|---|---|
OPENAI_API_KEY | ✅ Required | Key for fact extraction and embeddings. Entered in the deploy form. |
OPENAI_BASE_URL | Optional | An OpenAI-compatible endpoint (OpenRouter, a local model gateway) instead of OpenAI. |
MEM0_DEFAULT_LLM_MODEL | Optional | gpt-5-mini by default. The model that extracts facts. |
MEM0_DEFAULT_EMBEDDER_MODEL | Optional | text-embedding-3-small by default. Changing it later needs re-embedding. |
JWT_SECRET | 🔐 Auto-generated | Signs dashboard session tokens. |
POSTGRES_* | ✅ Auto-injected | Connection to the bundled Postgres over the private network. |
POSTGRES_COLLECTION_NAME | Optional | memories, the pgvector table name. |
DASHBOARD_URL, NEXT_PUBLIC_API_URL | ✅ Auto-injected | Each service's public URL, used for CORS and browser calls. |
MEM0_REF | Optional | v2.0.19, the Mem0 release tag both services build. Keep it the same on both. |
REQUEST_LOG_RETENTION_DAYS | Optional | 30 days of request log in the dashboard. |
Upgrading Mem0? Set the same new MEM0_REF on both mem0-api and mem0-dashboard and redeploy. They're released together.
Mem0 on Railway vs. Alternatives
| Mem0 on Railway | Mem0 Platform | Zep Cloud | Letta (self-hosted) | |
|---|---|---|---|---|
| Monthly cost | ~$5–10 plus model usage | $19 Starter, $249 Pro | $125 Flex | Hosting plus model usage |
| Self-hosted | ✅ Yes | ❌ No (enterprise on-prem only) | ❌ No | ✅ Yes |
| Request limits | ✅ None | ❌ 5,000 retrievals on Starter | ❌ 50,000 credits on Flex | ✅ None |
| Memory API for any agent | ✅ REST API | ✅ REST API | ✅ REST API | ⚠️ Agent framework |
| Admin dashboard | ✅ Included | ✅ Yes | ✅ Yes | ✅ Yes |
| Data in your own Postgres | ✅ Yes | ❌ Hosted | ❌ Hosted | ✅ Yes |
| License | ✅ Apache-2.0 | ❌ Proprietary hosting | ❌ Proprietary hosting | ✅ Apache-2.0 |
Dependencies for Mem0 Hosting
- Railway account. The Hobby plan ($5/month including $5 of usage) runs a small instance.
- An OpenAI API key, or an OpenAI-compatible endpoint, for extraction and embeddings.
- An agent or app that calls the API: any language works over REST, or use the Mem0 SDKs.
Deployment Dependencies
- Mem0 on GitHub: source code and releases
- Mem0 Documentation: API reference and open-source setup
- pgvector: the Postgres vector extension
- Railway Volumes Documentation: persistence
Implementation Details
The API image builds Mem0's server at the MEM0_REF tag. Its entrypoint creates the mem0_app database, runs Alembic migrations with retries, and serves uvicorn with proxy headers trusted, so the login rate limit sees real client IPs. A small relay adds IPv6 so other services on Railway's private network can reach it. The dashboard entrypoint injects the real public URLs into the prebuilt bundle and refuses to start if the API URL is missing.
Vectors live in Postgres with pgvector, so a single database backup covers memories, users and API keys. To scale, give mem0-api more RAM and CPU, or add replicas. Every request hits Postgres, so it stays the single source of truth.
Frequently Asked Questions
What is Mem0, and why self-host it? Mem0 gives AI agents long-term memory: it extracts facts from conversations and returns the relevant ones later. Self-hosting removes request caps and keeps personal memories in your own database.
How much does self-hosted Mem0 cost compared to the Mem0 Platform? About $5–10/month on Railway plus model usage, with no limit on adds or searches. The Mem0 Platform is $19/month for 5,000 retrievals and $249/month on Pro.
Why does the dashboard show errors when adding memories?
Usually the model key is missing or invalid. Check OPENAI_API_KEY (or OPENAI_BASE_URL) on mem0-api, redeploy, and look at the request log in the dashboard.
Do I lose memories when Railway redeploys?
No. Memories, users and keys are in Postgres on its volume, and history is on the /app/history volume. Both survive redeploys.
Can I use Anthropic, Gemini or a local model instead of OpenAI?
Yes. Choose Anthropic or Google in the dashboard's Configuration screen, or set OPENAI_BASE_URL to any OpenAI-compatible endpoint. Keep one embedding model; switching it needs re-embedding.
Does it work with LangChain, CrewAI or my own agent? Yes. Call the REST API from any language, or use the official Mem0 SDKs, which accept a self-hosted base URL.
Why Deploy and Host Mem0 on Railway?
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 get a self-hosted memory API and dashboard on your own Postgres, so your agents remember users with no per-request bill.
Template Content
mem0-api
gridalpha/mem0-railwayOPENAI_API_KEY
Required: extraction and embedding credential
mem0-dashboard
gridalpha/mem0-railway