---
title: "Deploy Mem0 OpenAI Agents"
description: "Long-term memory for OpenAI Agents SDK agents via Mem0"
category: "AI/ML"
url: https://railway.com/deploy/deploy-mem0-for-openai-agents-sdk
---

# Deploy Mem0 OpenAI Agents

Long-term memory for OpenAI Agents SDK agents via Mem0

**[Deploy Mem0 OpenAI Agents on Railway](https://railway.com/template/deploy-mem0-for-openai-agents-sdk)**

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

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

## Template content

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

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

## Documentation

# Deploy and Host self hosted Mem0 OpenAI Agents (Self-Hosted Long-Term Memory for Agents) on Railway

This template deploys a self-hosted Mem0 memory server on Railway, so your OpenAI Agents SDK agents can store and recall per-user facts on infrastructure you control.

## About Hosting Mem0 OpenAI Agents open-source software on Railway (self hosted self-hosted Mem0 long-term memory for OpenAI Agents SDK template)

This template runs the self-hosted Mem0 stack as four Railway services: mem0, a Caddy proxy and the only public entry point; mem0-api, a private FastAPI service; mem0-dashboard; and Postgres 18 with pgvector.

Railway handles Postgres, private networking and secrets.

## Why Deploy Mem0 OpenAI Agents, the Zep alternative on Railway (Railway Free Trial)

Zep is a strong pick if you want a temporal knowledge graph and you're fine paying for its cloud tier.

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

| Provider | What You Get with Railway | What You Get with the Other Provider |
| --- | --- | --- |
| DigitalOcean | Four services and Postgres from one template, with only the mem0 proxy public. | A Droplet you provision, where you install Docker, wire services, and manage TLS. |
| AWS | A managed deploy with no VPC or IAM setup before your first memory call. | Full networking control, but you assemble ECS or EC2, RDS, and routing yourself. |
| Hetzner | Services and Postgres ready in minutes with a public domain and health checks. | Low server cost, but you run the Compose stack, backups, and upgrades yourself. |

## Common Use Cases for hosted Mem0 OpenAI Agents

- **Support agent with account history:** The agent remembers a customer's plan, past tickets, and workarounds already tried, so nobody repeats the same story over weeks of follow-ups.
- **Personal assistant with preferences:** The assistant recalls meeting times, tone, and standing instructions between separate sessions, even after the chat history is gone.
- **Coding agent with project conventions:** The agent keeps naming rules, test framework choice, and repo layout per user_id, so it stops asking the same setup questions.
- **Sales agent with prospect notes:** The agent stores budget, decision makers, and objections from earlier calls and surfaces them before the next conversation.
- **In-house user memory:** Teams handling personal or customer data keep those memories on their own Railway servers instead of a third-party hosted platform, so they control storage and retention.

## Dependencies for Mem0 OpenAI Agents Docker hosted on Railway

Mem0 OpenAI Agents runs as four services.

### Deployment Dependencies for Managed Mem0 OpenAI Agents Service (AI Memory Layer)

- **mem0 (Caddy proxy):** Public port 8080, health check at /healthz.
- **mem0-api (FastAPI):** Port 8000, private, volume at /app/history, health check at /docs.
- **mem0-dashboard (Next.js):** Port 3000, private, health check at /api/health.
- **Postgres 18 with pgvector:** The railway database holds memories, and mem0_app holds users and keys.
- **Generated secrets:** JWT_SECRET, ADMIN_API_KEY, POSTGRES_PASSWORD.

### Implementation Details for Mem0 OpenAI Agents (Using Mem0 official docker image)

The API container waits for Postgres, enables pgvector, runs migrations, and listens dual-stack for Railway IPv6.

## How does Mem0 OpenAI Agents compare against other ways to give OpenAI Agents SDK agents long-term memory

### Mem0 OpenAI Agents vs OpenAI Agents SDK sessions (Built-in Session Memory)

- **Scope of memory:** Sessions keep one agent run's conversation history across turns. Mem0 extracts durable facts and stores them per user_id, so they return in later sessions.
- **Where it lives:** Sessions need no extra service. Mem0 runs as its own stack on Railway, one more thing to keep healthy.
- **Where sessions win:** For a single chat that only needs recent turns, sessions are simpler and cheaper.

### Mem0 OpenAI Agents vs Zep (Zep Alternative)

- **Memory model:** Zep builds a temporal knowledge graph that tracks how facts change. Mem0 stores facts as embeddings keyed by user_id, a flatter model.
- **Self-hosting:** Graphiti, Zep's open-source engine, is self-runnable, while Zep Cloud is commercial. This template runs the Mem0 server on your own Railway project.
- **Where Zep wins:** If you need reasoning over how facts changed over time, Zep's graph is the stronger fit.

### Mem0 OpenAI Agents vs Letta (Stateful Agent Server)

- **Architecture:** Letta is an Apache 2.0 stateful agent server, formerly MemGPT, and manages memory inside its own runtime. Mem0 leaves your agent loop alone and adds memory as tools.
- **Fit with the SDK:** Mem0 slots into the tools list you already have. Letta asks you to move the agent into its runtime.
- **Where Letta wins:** If you want the server to own agent state and memory editing end to end, Letta covers that. Mem0 only handles memory.

### Mem0 OpenAI Agents vs LangMem (LangChain Memory Library)

- **Packaging:** LangMem is a LangChain library for LangGraph apps. Mem0 is a standalone memory server reached over HTTP, with no LangGraph dependency.
- **Where LangMem wins:** If your app is already on LangGraph, LangMem fits with fewer moving parts.
- **Where Mem0 wins:** If your agents run on the OpenAI Agents SDK and you want memory behind a plain REST call, Mem0 is the better match.

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

1. Deploy the template on Railway and open the mem0 public domain.
2. Set OPENAI_API_KEY on mem0-api, or pick a provider on the dashboard Configuration page. Dashboard settings override env vars.
3. Under API Keys, create an m0sk_ key.
4. Set MEM0_URL to the public domain and MEM0_API_KEY to that key, then give the agent tools that call /search and /memories:

```python
import os, requests
from agents import Agent, Runner, function_tool

URL, HEADERS = os.environ["MEM0_URL"], {"X-API-Key": os.environ["MEM0_API_KEY"]}

@function_tool
def search_memory(query: str, user_id: str) -> str:
    """Look up saved facts about this user."""
    r = requests.post(f"{URL}/search", json={"query": query, "user_id": user_id}, headers=HEADERS, timeout=10)
    r.raise_for_status()
    return "\n".join(f"- {m['memory']}" for m in r.json().get("results", []))

@function_tool
def save_memory(content: str, user_id: str) -> str:
    """Store a durable fact about this user."""
    r = requests.post(f"{URL}/memories", json={"messages": [{"role": "user", "content": content}], "user_id": user_id}, headers=HEADERS, timeout=10)
    r.raise_for_status()
    return "Saved."

agent = Agent(name="Assistant", instructions="Search memory first. Save durable facts.", tools=[search_memory, save_memory])
print(Runner.run_sync(agent, "I'm on the Pro plan.").final_output)
```

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

Mem0 is Apache-2.0 and the full server and dashboard live in the upstream repo, so you can run the same stack on any VPS with Docker Compose.

### Clone the Repository

Clone the upstream repo and move into it.

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

### Install Dependencies

You need Docker and Docker Compose on the VPS.

```bash
docker --version
docker compose version
```

### Configure Environment Variables

Set your LLM key.

```bash
cp .env.example .env
# set OPENAI_API_KEY in .env, then keep the generated secrets
```

### Start the Mem0 OpenAI Agents Application

Bring the stack up and check health.

```bash
docker compose up -d
curl https://your-domain/healthz
```

## Official Pricing of Mem0 OpenAI Agents (Mem0 pricing)

Mem0 the platform has tiered pricing: Hobby is free with 10,000 add and 1,000 retrieval requests a month, Starter is 19 USD a month for 50,000 adds and 5,000 retrievals, and Pro is 249 USD a month for 500,000 adds and 50,000 retrievals with graph memory and analytics.

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

The open-source server is free; you pay for Railway and model API usage.

| | Hosted Mem0 platform | Self-hosted on Railway |
|---|---|---|
| Auth | MEM0_API_KEY | m0sk_ key sent as X-API-Key |
| Data location | Mem0's servers | Your Postgres |
| Graph memory | Pro tier | Not in this stack |

### Monthly cost of self hosting Mem0 OpenAI Agents on Railway

Expect roughly $10-20 a month for four small services plus Postgres at light use, on top of LLM and embedding API costs.

### System Requirements for Hosting Mem0 OpenAI Agents on a VPS

Plan for a Caddy proxy, the FastAPI memory API, the Next.js dashboard, and Postgres 18 with pgvector.

## Frequently Asked Questions (FAQs)

### Do SDK sessions already remember users?

Sessions keep conversation history for one agent run, but they don't extract durable facts or carry them into new sessions.

### Why does memory return provider_not_configured?

The stack boots without an LLM key, but memory endpoints return that error until you set OPENAI_API_KEY on mem0-api or pick a provider on the dashboard Configuration page.

### Why do I call the mem0 domain instead of mem0-api?

The mem0 Caddy proxy is the only public service. It sends API paths such as /memories and /search to the private mem0-api, so one domain serves both.

### How do I keep memories separate per customer?

Pass a stable user_id on every /memories and /search call.

### Can several apps share one server?

Yes, create a separate m0sk_ key per app under API Keys.


## Similar templates

- [Chat Chat](https://railway.com/deploy/-WWW5r) — Chat Chat, your own unified chat and search to AI platform.
- [Weaviate](https://railway.com/deploy/weaviate-1) — Vector database with hybrid search and an API key-protected API
- [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.

Open this page in a browser: https://railway.com/deploy/deploy-mem0-for-openai-agents-sdk
