Deploy LobeChat — Multi-Model AI Chat with RAG [Postgres]
Self-host LobeChat with history, RAG & 40+ providers — server mode
LobeChat
Just deployed
RustFS
Just deployed
/data
Just deployed
/var/lib/postgresql/data
Redis
Just deployed
/data
RustFS Init
Just deployed
Deploy and Host LobeChat on Railway
LobeChat is a polished, open-source AI chat platform — a self-hosted ChatGPT-style interface supporting 40+ model providers (OpenAI, Anthropic, Google, and more), a plugin system, and a document Knowledge Base with RAG. This template deploys the server-database version: LobeChat backed by PostgreSQL with pgvector and S3-compatible storage, so your chat history persists, syncs across devices, and the Knowledge Base actually works.
What This Template Deploys
| Service | Purpose |
|---|---|
| LobeChat | The chat UI, plugin system, and API (server-database build) on port 3210 |
| PostgreSQL + pgvector | Users, chat history, settings, and RAG document embeddings |
| MinIO (S3) | File and image storage — required for uploads and the Knowledge Base |
All services run on Railway's private network. This is the full server deployment, not the browser-only single-container mode.
About Hosting LobeChat
LobeChat ships in two very different modes, and choosing wrong is the most common self-hosting mistake.
The default single-container image stores everything in the browser — no server-side history, no cross-device sync, and the Knowledge Base doesn't function. It's fine for a personal scratchpad and useless as a team or multi-device deployment.
This template runs the server-database version, which persists everything properly. That requires three pieces wired together, and one of them catches almost everyone:
- PostgreSQL with pgvector stores accounts, history, and the RAG embeddings for the Knowledge Base
KEY_VAULTS_SECRETencrypts the API keys users store — set once, keep stable, or stored keys become unreadable- S3-compatible storage is mandatory, not optional. LobeChat has no local-disk fallback for file uploads, so without S3 the Knowledge Base and file attachments silently fail. This template includes MinIO as that storage layer
One more setting matters: APP_URL must be your real public domain. OAuth callbacks and async features like AI image generation make requests against it, and if it's wrong they fail without an obvious error.
LobeChat delegates inference to external providers, so no GPU is needed — connect cloud models and it runs on CPU.
Typical cost: ~$10–20/month on Railway for LobeChat, Postgres, and MinIO, plus your model providers' usage. LobeChat is Apache-2.0 with no paid tier for self-hosting.
How It Compares
| LobeChat server (this template) | LobeChat browser mode | ChatGPT Team | LibreChat | |
|---|---|---|---|---|
| Cost model | Flat ~$10–20/mo infra | ~$5/mo, no persistence | Per user/month | Self-hosted |
| Chat history | Server-side, synced | Browser only | Vendor | Server-side |
| Knowledge Base (RAG) | Yes | No | Limited | Yes |
| Providers | 40+ | 40+ | OpenAI only | Many |
| Cross-device sync | Yes | No | Yes | Yes |
| Self-hostable | Yes | Yes | No | Yes |
ChatGPT Team is polished but OpenAI-only and per-seat. LibreChat is a strong alternative aimed at multi-user teams. LobeChat's server mode stands out on interface polish, its plugin ecosystem, and 40+ providers — with the persistence and RAG that browser mode lacks.
Deploy in Under 5 Minutes
- Click Deploy on Railway — LobeChat, PostgreSQL, and MinIO build automatically (~4 minutes)
- Confirm
KEY_VAULTS_SECRETandNEXT_AUTH_SECRETare generated (eachopenssl rand -base64 32) - Set
APP_URLto your Railway public domain — OAuth and image generation depend on it - Confirm the
S3_*variables point at the MinIO service - Open your domain, create an account, then add provider API keys under Settings → Model Provider
Keys are encrypted with KEY_VAULTS_SECRET and stored per user, so each person can bring their own.
Common Use Cases
- Private multi-provider AI hub — one polished interface across OpenAI, Anthropic, Google, and 40+ providers, keys encrypted server-side
- Team AI workspace — server-side history and cross-device sync so a whole team shares one deployment
- Document Q&A with RAG — upload files to the Knowledge Base and query them with any connected model
- Plugin-extended assistant — web search, code execution, and other plugins extend what the chat can do
- Provider cost management — centralize keys and usage across models instead of scattering them across apps
- Privacy-first AI — conversations and documents stay on infrastructure you control
Configuration
| Variable | Required | Description |
|---|---|---|
DATABASE_URL | Auto-injected | PostgreSQL connection via Railway reference variable |
KEY_VAULTS_SECRET | Required | Encrypts stored provider keys — openssl rand -base64 32, keep stable |
NEXT_AUTH_SECRET | Required | Authentication session secret — openssl rand -base64 32 |
APP_URL | Required | Your Railway public domain — OAuth and async features depend on it |
NEXT_AUTH_SSO_PROVIDERS | Optional | SSO providers, e.g. github, auth0, logto |
S3_ENDPOINT | Required | MinIO/S3 endpoint — required for uploads and Knowledge Base |
S3_BUCKET | Required | Storage bucket name |
S3_ACCESS_KEY_ID | Required | S3 access key |
S3_SECRET_ACCESS_KEY | Required | S3 secret key |
S3_PUBLIC_DOMAIN | Required | Public URL for served files |
NEXT_PUBLIC_ENABLE_NEXT_AUTH | Optional | Set 1 to enable authentication |
S3 storage is required, not optional. LobeChat has no local-disk fallback for uploads. Without working S3, file attachments and the Knowledge Base silently fail. This template includes MinIO for it.
Keep
KEY_VAULTS_SECRETandNEXT_AUTH_SECRETstable. The first encrypts stored provider keys; changing it makes them unreadable. Both are generated at deploy — back them up and don't rotate them.
Dependencies for LobeChat Hosting
- Railway account — expect ~$10–20/month for LobeChat, Postgres, and MinIO
- At least one model provider API key (OpenAI, Anthropic, Google, etc.)
- S3-compatible storage (MinIO included) for uploads and the Knowledge Base
- Optional: an OAuth provider (GitHub, Auth0, Logto) for SSO and team features
Deployment Dependencies
- LobeChat GitHub Repository
- LobeChat Self-Hosting Documentation
- Server Database Deployment Guide
- Railway Volumes Documentation
Implementation Details
The template runs the lobehub/lobe-chat-database image on port 3210 — the server-database build, not the browser-only default — against a PostgreSQL service with the pgvector extension and a MinIO service for S3-compatible storage. All three communicate over Railway's private network.
KEY_VAULTS_SECRET encrypts the provider API keys users store, and NEXT_AUTH_SECRET secures authentication sessions; both are generated at deploy and must remain stable, since changing the vault secret renders stored keys unreadable. pgvector powers the Knowledge Base: uploaded documents are embedded and stored for semantic search, which is why the database extension and the S3 storage layer are both required rather than optional.
APP_URL must match the public domain, because OAuth callbacks and LobeChat's async features (such as AI image generation) make requests against it — a common cause of silent failures when it's left at a default. Inference is delegated to external providers, so the deployment runs on CPU with no GPU.
Frequently Asked Questions
Why is S3 storage required? LobeChat's server version stores file uploads and Knowledge Base documents in S3-compatible storage, with no local-disk fallback. Without it, attachments and RAG silently fail. This template includes MinIO so both work out of the box.
What's the difference from the single-container version? The default single-container image keeps everything in the browser — no server history, no sync, no working Knowledge Base. This template runs the server-database version, which persists history, syncs across devices, and enables RAG.
How do I add API keys? After logging in, go to Settings → Model Provider and enter keys for OpenAI, Anthropic, Google, and 40+ others. They're encrypted with KEY_VAULTS_SECRET and stored per user.
Does my chat history persist? Yes. In server-database mode, history, settings, and Knowledge Base data live in PostgreSQL and persist across redeploys and devices. Back the database up on a schedule.
Can I use local models like Ollama? LobeChat supports Ollama as a provider, but Ollama needs a GPU, which Railway doesn't provide. Point LobeChat at an Ollama instance running on a separate GPU host.
Why does image generation fail? Usually APP_URL doesn't match your real domain. LobeChat's async features call back against it, so it must be set correctly.
Is it free? Yes. LobeChat is Apache-2.0 with the full feature set available self-hosted and no paid tier.
Why Deploy LobeChat 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 LobeChat on Railway you get the full server-database experience with the pieces that browser mode lacks — PostgreSQL with pgvector, MinIO for uploads and RAG, encrypted key vaults, and automatic HTTPS. Persistent history, a working Knowledge Base, 40+ providers, and your conversations on infrastructure you own.
Template Content
