Self-Hosting LibreChat: Multi-AI Chat Interface for OpenAI, Claude & Local Models

Paying for ChatGPT Plus, Claude Pro, and Gemini Advanced separately gets expensive fast — and you’re still locked into each provider’s individual interface. LibreChat gives you a single, self-hosted ChatGPT-style UI that connects to all of them at once: OpenAI, Anthropic, Google, local models through Ollama, and dozens more through OpenRouter and custom endpoints.

It’s not just a chat wrapper. LibreChat includes conversation branching, file uploads, image generation, a code interpreter, RAG (retrieval-augmented generation) with your own documents, MCP tool support, multi-user auth, and an agent system that lets you build custom AI assistants — all from one interface you fully control.

The project has over 22,000 GitHub stars and ships regular updates. Think of it as the Jellyfin of AI chat: open source, self-hosted, and steadily closing the gap with commercial offerings.

LibreChat vs Other AI Interfaces

FeatureLibreChatOpen WebUILobeChatChatGPT
Multi-provider✅ NativeVia OpenAI-compat✅ Native❌ OpenAI only
Local models (Ollama)✅ Native focus
RAG / file chat✅ Built-in✅ Built-inPlugin
Code interpreter✅ Sandboxed
Agents / tools✅ + MCP✅ Plugin✅ GPTs
Multi-user auth✅ OAuth/LDAP✅ Basic
Conversation branching
Image generation✅ DALL-E/SD/Flux✅ DALL-E
LicenseMITMITMITProprietary
Self-hosted

Choose LibreChat if you want a polished, multi-provider interface with enterprise features like LDAP auth, conversation branching, and built-in RAG. Choose Open WebUI if your primary focus is local models with Ollama. Choose LobeChat if you want a plugin ecosystem and don’t need multi-user support.

Prerequisites

  • A Linux server with Docker and Docker Compose installed
  • At least 2GB RAM (4GB+ recommended with RAG enabled)
  • API keys for your chosen providers (OpenAI, Anthropic, Google, etc.)
  • Optional: Ollama running locally for local model support
  • Optional: A domain name with a reverse proxy for HTTPS access

Docker Compose Setup

LibreChat’s default stack includes MongoDB for chat storage, Meilisearch for message search, and an optional RAG API with pgvector for document chat. Here’s a production-ready setup:

# docker-compose.yml
services:
  librechat:
    container_name: librechat
    image: registry.librechat.ai/danny-avila/librechat-dev:latest
    ports:
      - "3080:3080"
    depends_on:
      - mongodb
      - meilisearch
    restart: unless-stopped
    extra_hosts:
      - "host.docker.internal:host-gateway"
    environment:
      - HOST=0.0.0.0
      - PORT=3080
      - MONGO_URI=mongodb://mongodb:27017/LibreChat
      - MEILI_HOST=http://meilisearch:7700
      - RAG_PORT=8000
      - RAG_API_URL=http://rag_api:8000
    volumes:
      - ./.env:/app/.env
      - ./images:/app/client/public/images
      - ./uploads:/app/uploads
      - ./logs:/app/logs

  mongodb:
    container_name: librechat-mongodb
    image: mongo:8.0
    restart: unless-stopped
    volumes:
      - mongodb_data:/data/db
    command: mongod --noauth

  meilisearch:
    container_name: librechat-meilisearch
    image: getmeili/meilisearch:v1.35.1
    restart: unless-stopped
    environment:
      - MEILI_HOST=http://meilisearch:7700
      - MEILI_NO_ANALYTICS=true
      - MEILI_MASTER_KEY=${MEILI_MASTER_KEY}
    volumes:
      - meilisearch_data:/meili_data

  # Optional: RAG API for document chat
  vectordb:
    container_name: librechat-vectordb
    image: pgvector/pgvector:0.8.0-pg15-trixie
    restart: unless-stopped
    environment:
      POSTGRES_DB: librechat_rag
      POSTGRES_USER: librechat
      POSTGRES_PASSWORD: ${RAG_DB_PASSWORD:-changeme}
    volumes:
      - pgdata:/var/lib/postgresql/data

  rag_api:
    container_name: librechat-rag
    image: registry.librechat.ai/danny-avila/librechat-rag-api-dev-lite:latest
    restart: unless-stopped
    depends_on:
      - vectordb
    environment:
      - DB_HOST=vectordb
      - RAG_PORT=8000
    env_file:
      - .env

volumes:
  mongodb_data:
  meilisearch_data:
  pgdata:

Environment Configuration

Create your .env file from the extensive template LibreChat provides. Here are the essential settings:

# .env

# Server
HOST=localhost
PORT=3080
DOMAIN_CLIENT=http://localhost:3080
DOMAIN_SERVER=http://localhost:3080

# Credentials encryption key (generate with: openssl rand -hex 32)
CREDS_KEY=your_random_32_hex_string_here
CREDS_IV=your_random_16_hex_string_here

# JWT secret (generate with: openssl rand -hex 32)
JWT_SECRET=your_jwt_secret_here
JWT_REFRESH_SECRET=your_jwt_refresh_secret_here

# Meilisearch (generate with: openssl rand -base64 20)
MEILI_MASTER_KEY=your_meili_key_here

# Allow registration (set to false after creating your account)
ALLOW_REGISTRATION=true
ALLOW_SOCIAL_LOGIN=false
ALLOW_SOCIAL_REGISTRATION=false

#==== AI Provider API Keys ====#

# OpenAI
OPENAI_API_KEY=sk-your-openai-key

# Anthropic (Claude)
ANTHROPIC_API_KEY=sk-ant-your-anthropic-key

# Google (Gemini)
GOOGLE_KEY=your-google-ai-key

# Optional: Control which endpoints appear
# ENDPOINTS=openAI,anthropic,google

Generate your secrets before first launch:

# Generate all required secrets
echo "CREDS_KEY=$(openssl rand -hex 32)" >> .env
echo "CREDS_IV=$(openssl rand -hex 16)" >> .env
echo "JWT_SECRET=$(openssl rand -hex 32)" >> .env
echo "JWT_REFRESH_SECRET=$(openssl rand -hex 32)" >> .env
echo "MEILI_MASTER_KEY=$(openssl rand -base64 20)" >> .env

Connecting AI Providers

OpenAI, Anthropic & Google

The simplest setup — just add API keys to your .env file as shown above. LibreChat automatically detects available models from each provider.

Local Models via Ollama

If you’re running Ollama on the same machine, LibreChat connects to it through the host.docker.internal bridge. Create a librechat.yaml config file:

# librechat.yaml
version: 1.2.1
cache: true

endpoints:
  custom:
    - name: "Ollama"
      apiURL: "http://host.docker.internal:11434/v1/"
      baseURL: "http://host.docker.internal:11434/v1/"
      models:
        default: ["llama3.1:8b", "mistral:7b", "codestral:22b", "gemma2:9b"]
        fetch: true
      titleConvo: true
      titleModel: "llama3.1:8b"
      summarize: false
      forcePrompt: false
      modelDisplayLabel: "Ollama"

Mount this config in your compose file by adding to the librechat service volumes:

- ./librechat.yaml:/app/librechat.yaml

OpenRouter (100+ Models)

Access models from dozens of providers through a single API key:

# In librechat.yaml under endpoints.custom:
    - name: "OpenRouter"
      apiURL: "https://openrouter.ai/api/v1/chat/completions"
      baseURL: "https://openrouter.ai/api/v1/"
      models:
        default: ["meta-llama/llama-3.1-405b", "anthropic/claude-3.5-sonnet"]
        fetch: true
      titleConvo: true
      modelDisplayLabel: "OpenRouter"

Set OPENROUTER_KEY in your .env and reference it in the yaml config.

First Launch

# Start the stack
docker compose up -d

# Check logs
docker compose logs -f librechat

Navigate to http://your-server:3080. You’ll see a registration page — create your admin account, then set ALLOW_REGISTRATION=false in .env and restart to lock down sign-ups.

The interface will feel immediately familiar if you’ve used ChatGPT. The key difference: a model selector dropdown that lets you switch between providers mid-conversation.

Key Features

Conversation Branching

One of LibreChat’s standout features. Click on any message to edit it or create a branch — you can explore different responses from different models to the same prompt without losing your original conversation thread. This is something even ChatGPT doesn’t offer.

Agents & MCP Tools

LibreChat includes a no-code agent builder. Create custom assistants with specific system prompts, attach tools (web search, code execution, file handling), and share them with other users on your instance.

MCP (Model Context Protocol) support means you can connect external tool servers — the same protocol used by Claude Desktop and other AI tools.

Code Interpreter

A sandboxed execution environment supporting Python, Node.js, Go, C/C++, Java, PHP, and Rust. Upload files, run analysis, generate plots — similar to ChatGPT’s Code Interpreter but running on your own hardware.

RAG: Chat With Your Documents

With the RAG API enabled (included in our compose setup), you can upload PDFs, text files, and other documents. LibreChat chunks them, generates embeddings, stores them in pgvector, and retrieves relevant context when you ask questions. Your documents never leave your server.

Presets & Prompt Library

Save model configurations as presets — temperature, system prompt, specific model — and switch between them instantly. Create a “coding assistant” preset with GPT-4o at low temperature and a “creative writing” preset with Claude at high temperature.

Search Everything

Meilisearch indexes all your conversations for fast, typo-tolerant full-text search. Find that one conversation from three months ago in seconds.

Multi-User Setup

LibreChat supports multiple authentication methods:

# .env — OAuth2 example (Google)
GOOGLE_CLIENT_ID=your-google-client-id
GOOGLE_CLIENT_SECRET=your-google-client-secret
GOOGLE_CALLBACK_URL=/oauth/google/callback

# LDAP
LDAP_URL=ldap://your-ldap-server:389
LDAP_BIND_DN=cn=admin,dc=example,dc=com
LDAP_BIND_CREDENTIALS=your_password
LDAP_USER_SEARCH_BASE=ou=users,dc=example,dc=com

You can also set per-user token limits to control API spend:

# In librechat.yaml
registration:
  socialLogins: ["google", "github"]
  allowedDomains:
    - "yourdomain.com"

rateLimits:
  fileUploads:
    ipMax: 100
    ipWindowInMinutes: 60
    userMax: 50
    userWindowInMinutes: 60

For enterprise SSO, pair with Authentik or Authelia as your identity provider.

Reverse Proxy Configuration

Caddy

c}hat.ryeovuerrdsoem_apirno.xcyomlo{calhost:3080

Nginx

server {
    listen 443 ssl http2;
    server_name chat.yourdomain.com;

    ssl_certificate /etc/letsencrypt/live/chat.yourdomain.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/chat.yourdomain.com/privkey.pem;

    client_max_body_size 100M;

    location / {
        proxy_pass http://localhost:3080;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_buffering off;
        proxy_cache off;
    }
}

WebSocket support is required for streaming responses. The proxy_buffering off directive ensures tokens stream to your browser in real-time rather than arriving in chunks.

Update your .env when using a reverse proxy:

DOMAIN_CLIENT=https://chat.yourdomain.com
DOMAIN_SERVER=https://chat.yourdomain.com
TRUST_PROXY=1

Backup & Restore

MongoDB (Conversations)

# Backup
docker exec librechat-mongodb mongodump \
  --db LibreChat \
  --out /data/db/backup

docker cp librechat-mongodb:/data/db/backup ./backup-$(date +%Y%m%d)

# Restore
docker cp ./backup-20260321 librechat-mongodb:/data/db/backup
docker exec librechat-mongodb mongorestore \
  --db LibreChat \
  /data/db/backup/LibreChat

File Uploads & Images

# Backup uploads and images
tar czf librechat-files-$(date +%Y%m%d).tar.gz uploads/ images/

Full Backup Script

#!/bin/bash
BACKUP_DIR="./backups/$(date +%Y%m%d)"
mkdir -p "$BACKUP_DIR"

# MongoDB
docker exec librechat-mongodb mongodump --db LibreChat --out /tmp/backup
docker cp librechat-mongodb:/tmp/backup "$BACKUP_DIR/mongodb"

# Files
cp -r uploads/ "$BACKUP_DIR/uploads"
cp -r images/ "$BACKUP_DIR/images"
cp .env "$BACKUP_DIR/.env"
cp librechat.yaml "$BACKUP_DIR/librechat.yaml" 2>/dev/null

echo "Backup complete: $BACKUP_DIR"

Automate this with a cron job or pair with Kopia for encrypted, deduplicated backups.

Updating

docker compose pull
docker compose up -d

LibreChat handles database migrations automatically on startup. Check the changelog before major updates — occasionally a librechat.yaml schema change requires adjustments.

Troubleshooting

Blank screen or API errors after startup: Check that all secrets in .env are properly generated. Missing CREDS_KEY or JWT_SECRET causes silent failures. Regenerate them and restart.

Models not appearing: Verify your API keys are correct and the endpoint is enabled. Check ENDPOINTS in .env — if set, only listed endpoints appear. Remove the line to show all configured providers.

Ollama connection refused: Ensure extra_hosts: ["host.docker.internal:host-gateway"] is in your compose file. On Linux, you may also need network_mode: host or to set the Ollama URL to your machine’s actual IP.

Streaming not working behind reverse proxy: Make sure WebSocket upgrade headers are configured (see Nginx config above). Also check that proxy_buffering off is set.

High memory usage: MongoDB and Meilisearch can be hungry. Set resource limits in your compose file:

  mongodb:
    deploy:
      resources:
        limits:
          memory: 1G

  meilisearch:
    deploy:
      resources:
        limits:
          memory: 512M

RAG not working: Verify the vectordb and rag_api containers are running. Check rag_api logs: docker compose logs rag_api. The RAG API needs a valid embedding model configured — by default it uses OpenAI embeddings, so OPENAI_API_KEY must be set.

File upload failures: Check client_max_body_size in Nginx (default 1MB is too small). For large files with RAG, you may also need to increase the RAG API timeout.

Power User Tips

  • Custom endpoints: Connect any OpenAI-compatible API (vLLM, text-generation-webui, LiteLLM) via librechat.yaml custom endpoints — no code changes needed
  • Prompt library: Create shared prompts with variables for your team — great for standardizing AI workflows
  • Conversation forking: Fork any conversation at any point to explore different directions without losing the original
  • Artifacts: Generate React components, HTML pages, and Mermaid diagrams directly in chat with the code artifacts feature
  • Speech support: Enable TTS/STT with OpenAI, Azure, or ElevenLabs for voice interaction
  • Langfuse tracing: Add LANGFUSE_PUBLIC_KEY and LANGFUSE_SECRET_KEY to .env for full observability into token usage and response quality across all providers
  • Token tracking: Built-in spend tracking per user helps manage API costs when running a shared instance

Wrapping Up

LibreChat hits a sweet spot: it’s polished enough to replace ChatGPT Plus for daily use, flexible enough to integrate with local models and custom APIs, and feature-rich enough to serve as a shared AI platform for a small team.

The killer feature isn’t any single thing — it’s having OpenAI, Claude, Gemini, and your local Ollama models all in one tabbed interface where you can switch providers mid-conversation and search across everything. Add RAG for document chat and agents for custom workflows, and you’ve built yourself an AI workbench that rivals commercial offerings.

For a complete self-hosting setup, pair LibreChat with Caddy for automatic HTTPS, Authentik for SSO, and Kopia for automated backups. If you’re running local models, check out our Ollama guide for optimizing inference on your hardware.


Useful Links: