Deploy Mem0

Self-hosted Mem0: long-term memory API for AI agents, with a dashboard.

Deploy Mem0

Just deployed

/app/history

Just deployed

/var/lib/postgresql/data

Deploy and Host Mem0 on Railway

Mem0, the memory layer for AI agents

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

ServicePurpose
mem0-apiThe Mem0 REST server (FastAPI) on port 8000 with a public HTTPS domain. Your agents and apps call it to add and search memories.
mem0-dashboardThe Next.js admin dashboard on port 3000: first-run setup, API keys, model configuration and the request log.
PostgresPostgres 18 holding the vector store (memories table, pgvector) and a mem0_app database for users, keys and settings.
Persistent VolumeMounted 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

  1. Click Deploy on Railway and paste your OPENAI_API_KEY. Both services build from source (about 5–8 minutes).
  2. Open the mem0-dashboard domain and complete the setup wizard to create your admin account.
  3. Create an API key in the dashboard.
  4. Point your agent or app at the mem0-api domain with that key, then add memories after each conversation.
  5. Search memories before each response, filtered by user_id, agent_id or run_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

VariableRequiredDescription
OPENAI_API_KEY✅ RequiredKey for fact extraction and embeddings. Entered in the deploy form.
OPENAI_BASE_URLOptionalAn OpenAI-compatible endpoint (OpenRouter, a local model gateway) instead of OpenAI.
MEM0_DEFAULT_LLM_MODELOptionalgpt-5-mini by default. The model that extracts facts.
MEM0_DEFAULT_EMBEDDER_MODELOptionaltext-embedding-3-small by default. Changing it later needs re-embedding.
JWT_SECRET🔐 Auto-generatedSigns dashboard session tokens.
POSTGRES_*✅ Auto-injectedConnection to the bundled Postgres over the private network.
POSTGRES_COLLECTION_NAMEOptionalmemories, the pgvector table name.
DASHBOARD_URL, NEXT_PUBLIC_API_URL✅ Auto-injectedEach service's public URL, used for CORS and browser calls.
MEM0_REFOptionalv2.0.19, the Mem0 release tag both services build. Keep it the same on both.
REQUEST_LOG_RETENTION_DAYSOptional30 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 RailwayMem0 PlatformZep CloudLetta (self-hosted)
Monthly cost~$5–10 plus model usage$19 Starter, $249 Pro$125 FlexHosting 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

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

More templates in this category

View Template
Chat Chat
Chat Chat, your own unified chat and search to AI platform.

okisdev
117
View Template
NEW
Möbius v0.1 Personal AI OS
Self-hosted AI agent that builds and runs apps for you, with memory.

bento
1
View Template
stella
Self-host stella with web, API, Postgres, Redis, and object storage.

Jan Kubica
7