Librechat.ai is an open source AI chat platform that you can host yourself. In this tutorial, we will install Librechat AI using Docker and Traefik.
I’ve had some hoops to jump through to get everything working, so I thought I’d share the steps I took to get it up and running.
This guide assumes you are using an external network called web to route all your traffic through Traefik.
The official installation guide can be found here. Follow the guide to set up the required environment variables and start the Docker containers.
docker-compose.override.yml file 1version: '3.4' 2 3services: 4 api: 5 labels: 6 - 'traefik.enable=true' 7 - 'traefik.http.routers.librechat.rule=Host(`your.domain.example.com`)' 8 - 'traefik.http.routers.librechat.tls=true' 9 - 'traefik.http.routers.librechat.tls.certresolver=lets-encrypt'10 - 'traefik.http.services.librechat.loadbalancer.server.port=3080'11 networks:12 - web13 - librechat_default14 volumes:15 - ./librechat.yaml:/app/librechat.yaml16 17networks:18 web:19 external: true20 librechat_default:21 external: true
.env fileTo get the keys you may use the following script, place it in a file and run the file with node file.js:
1const crypto = require('crypto') 2 3// Generate a 32-byte key (64 characters in hex) 4const key = crypto.randomBytes(32).toString('hex') 5 6// Generate a 16-byte IV (32 characters in hex) 7const iv = crypto.randomBytes(16).toString('hex') 8 9// Generate a 32-byte key (64 characters in hex)10const jwt = crypto.randomBytes(32).toString('hex')11 12// Generate a 32-byte key (64 characters in hex)13const jwt2 = crypto.randomBytes(32).toString('hex')14 15console.log(`CREDS_KEY=${key}`)16console.log(`CREDS_IV=${iv}`)17console.log(`JWT_SECRET=${jwt}`)18console.log(`JWT_REFRESH_SECRET=${jwt2}`)
After that you can adjust the .env file:
1HOST=localhost 2PORT=3080 3 4DOMAIN_CLIENT=https://your.domain.example.com 5DOMAIN_SERVER=https://your.domain.example.com 6 7OPENAI_API_KEY=your-key 8ASSISTANTS_API_KEY=your-key 9APP_TITLE="a fancy title"10 11CREDS_KEY=f151369e25852102edfa394fd034df5ac492c2a0028acaa51260402916488c6512CREDS_IV=13272260bd313fd2d032ddcd70b7576913JWT_SECRET=4d10e5b41de2d88a819b0e4b8600d1834c25356a44323cfb1bd3a8e839688b0414JWT_REFRESH_SECRET=4f73e40aadf694f829b9980d0224cd14783d791f5744627af9d94ed71dc3494315 16ALLOW_REGISTRATION=true
After adjusting the files, you can start the containers with the following command:
1docker-compose up -d
That should be it! You should now be able to access Librechat AI at https://your.domain.example.com.
You might find these related articles helpful or interesting, make sure to check them out!
I hope you found this article useful! 😊.