Railway

Deploy Letta | Open-Source Stateful AI Agent Framework

Self-host Letta (MemGPT). Build AI agents that remember everything

Deploy Letta | Open-Source Stateful AI Agent Framework

Just deployed

Just deployed

/var/lib/postgresql/data

Letta logo

Deploy and Host Letta on Railway

Deploy Letta on Railway to get a production-ready AI agent platform with persistent memory and stateful reasoning. Letta (formerly MemGPT) is an open-source framework for building AI agents that learn and self-improve over time through advanced long-term memory management.

Self-host Letta on Railway with this template that pre-configures the Letta server, a PostgreSQL database with pgvector for vector embeddings, and password-protected API access. Connect your own LLM provider (OpenAI, Anthropic, or local models) and start building agents immediately.

Getting Started with Letta on Railway

After deployment completes, visit your Railway-generated public URL. The Letta server exposes a REST API at port 8283 with password authentication enabled by default. Use the LETTA_SERVER_PASSWORD from your Railway environment variables to authenticate API requests.

Install the Letta Python SDK to interact with your self-hosted server:

pip install letta

Connect to your Railway-hosted Letta instance and create your first agent:

from letta import Letta

client = Letta(
    base_url="https://your-app.up.railway.app",
    token="your-letta-server-password"
)

agent = client.agents.create(
    name="my-agent",
    model="openai/gpt-4o",
    embedding="letta/letta-free"
)

response = client.agents.messages.create(
    agent_id=agent.id,
    messages=[{"role": "user", "content": "Hello! Remember my name is Alex."}]
)

Add your LLM provider API key (e.g. OPENAI_API_KEY) as an environment variable in Railway to unlock model access.

About Hosting Letta

Letta is a platform for building stateful AI agents — AI systems with advanced memory that can learn and self-improve over time. Unlike stateless LLM API calls, Letta agents maintain persistent memory across conversations, enabling them to remember context, preferences, and learned information indefinitely.

Key features of self-hosted Letta include:

  • Long-term memory — agents retain and recall information across sessions using vector-based retrieval
  • Multi-provider LLM support — connect OpenAI, Anthropic, Google Gemini, local Ollama, or vLLM backends
  • REST API and Python SDK — full programmatic control over agents, memory, and conversations
  • Tool use — agents can execute custom Python functions and external API calls
  • Built-in memory management — automatic archival memory, conversation summaries, and context window optimization
  • Multi-agent orchestration — build systems with multiple specialized agents that collaborate

The template deploys two services: the Letta application server and a PostgreSQL database with pgvector for storing agent memory embeddings.

Why Deploy Letta on Railway

  • One-click deployment with PostgreSQL and pgvector pre-configured
  • Persistent agent memory survives container restarts via external database
  • Password-protected API endpoint out of the box
  • Scale server resources independently from database storage
  • No vendor lock-in — bring any LLM provider key

Common Use Cases for Self-Hosted Letta

  • AI assistants with memory — build chatbots that remember user preferences, past conversations, and context across sessions
  • Autonomous research agents — deploy agents that continuously gather, analyze, and synthesize information from multiple sources
  • Customer support automation — create agents that learn from ticket history and improve response quality over time
  • Internal knowledge workers — build agents that ingest company documentation and answer employee questions with institutional memory

Dependencies for Letta on Railway

  • Letta Serverletta/letta:latest — the main application server exposing the REST API
  • PostgreSQL + pgvectorpgvector/pgvector:pg16 — stores agent state, memory embeddings, and conversation history

Environment Variables Reference for Letta

VariableDescriptionDefault
LETTA_PG_URIPostgreSQL connection string with pgvectorSet via service reference
SECUREEnable password authenticationtrue
LETTA_SERVER_PASSWORDAPI access passwordGenerated at deploy
OPENAI_API_KEYOpenAI API key (optional)Not set
ANTHROPIC_API_KEYAnthropic API key (optional)Not set
PORTHTTP server listening port8283

Deployment Dependencies

Hardware Requirements for Self-Hosting Letta

ResourceMinimumRecommended
CPU1 vCPU2 vCPU
RAM1 GB2 GB
Storage1 GB (app) + 1 GB (DB)5 GB+ (DB grows with agent data)
RuntimeDockerDocker

Letta itself is lightweight — resource usage scales primarily with the number of concurrent agents and the size of stored memory. The PostgreSQL database with pgvector handles the heavy lifting for vector similarity search.

Self-Hosting Letta with Docker

Run Letta locally with Docker Compose using an external PostgreSQL database:

services:
  letta_db:
    image: pgvector/pgvector:pg16
    environment:
      POSTGRES_USER: letta
      POSTGRES_PASSWORD: changeme
      POSTGRES_DB: letta
    volumes:
      - pgdata:/var/lib/postgresql/data

  letta:
    image: letta/letta:latest
    ports:
      - "8283:8283"
    environment:
      LETTA_PG_URI: postgresql://letta:changeme@letta_db:5432/letta
      SECURE: "true"
      LETTA_SERVER_PASSWORD: your-secure-password
    depends_on:
      - letta_db

volumes:
  pgdata:

Or run standalone with embedded PostgreSQL:

docker run -d \
  -v ~/.letta/.persist/pgdata:/var/lib/postgresql/data \
  -p 8283:8283 \
  -e SECURE=true \
  -e LETTA_SERVER_PASSWORD=your-secure-password \
  letta/letta:latest

How Much Does Letta Cost to Self-Host?

Letta is fully open-source under the Apache 2.0 license with no licensing fees. Self-hosting on Railway costs approximately $5-10/month for basic usage, covering compute and database storage. You pay separately for LLM API usage to your chosen provider (OpenAI, Anthropic, etc.). Letta Cloud offers a free tier with limited requests, but self-hosting gives you unlimited agents and full data ownership.

Letta vs LangGraph vs CrewAI

FeatureLettaLangGraphCrewAI
Primary focusStateful agents with memoryGraph-based workflowsRole-based multi-agent
Long-term memoryBuilt-in, persistentManual implementationLimited
Self-host complexitySingle Docker imagePart of LangChain stackRequires custom setup
LLM provider supportAny (OpenAI, Anthropic, local)AnyAny
Best forAgents that learn over timeComplex workflow pipelinesTeam-based task execution
LicenseApache 2.0MITMIT

Letta's differentiator is its first-class support for persistent agent memory — agents remember everything across sessions without manual state management. Choose LangGraph for complex multi-step workflows with branching logic, or CrewAI for coordinating teams of specialized agents on structured tasks.

FAQ

What is Letta and why should you self-host it? Letta is an open-source AI agent framework that gives agents persistent long-term memory. Self-hosting gives you full control over your data, unlimited agent creation, and the ability to connect any LLM provider without per-request fees from Letta's cloud service.

What does this Railway template deploy for Letta? This template deploys two services: the Letta application server (letta/letta:latest) and a PostgreSQL database with pgvector extension (pgvector/pgvector:pg16). The database stores agent state, conversation history, and vector embeddings for memory retrieval.

Why does Letta on Railway need PostgreSQL with pgvector? Letta uses vector embeddings for its memory retrieval system. The pgvector extension enables efficient similarity search on these embeddings, allowing agents to quickly recall relevant memories from potentially millions of stored interactions. Standard PostgreSQL without pgvector cannot perform these vector operations.

How do I connect OpenAI or Anthropic to self-hosted Letta? Add your provider's API key as an environment variable in Railway. Set OPENAI_API_KEY for OpenAI models or ANTHROPIC_API_KEY for Claude models. Letta automatically detects available providers and makes their models available for agent creation.

Can I use local LLMs with Letta on Railway instead of cloud APIs? Letta supports Ollama and vLLM as local LLM backends. However, running a local LLM on Railway requires significant resources (8GB+ RAM for most models). For Railway deployments, cloud LLM APIs (OpenAI, Anthropic) are more practical. You can also point Letta at an externally-hosted Ollama instance via OLLAMA_BASE_URL.

How do I authenticate API requests to self-hosted Letta? Set SECURE=true and LETTA_SERVER_PASSWORD in your environment variables. All API requests must include the password as a Bearer token in the Authorization header: Authorization: Bearer your-password.


Template Content

More templates in this category

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

okisdev
View Template
EchoDeck
Generate a mp4 from powerpoint with TTS

Fixed Scope
View Template
Rift
Rift Its a OSS AI Chat for teams

Compound