Deploy an AI Assistant Gateway in the Cloud: From Server Setup to Bot Integration
This guide explains how to deploy an AI assistant gateway on a cloud server, from sizing and SSH/firewall hardening to Docker installation, source preparation, environment variables, and Docker Compose configuration. It shows how the gateway connects model providers with chat platforms for message routing, session management, and skill invocation.
As large language model capabilities mature, asking questions only in a web chat box is no longer enough for daily work. More developers want to connect models to office groups and instant messaging tools so the model can respond to messages, call tools, and remember history at any time. The AI assistant gateway fills this connection role: it connects to model providers on one side and chat platforms on the other, and handles routing, session management, and skill invocation in between.
This article explains each step in deployment order and highlights the places where errors are easy to make. In the examples, repository URLs, image versions, domains, and keys must be replaced with your own actual values.
1. Choose a Cloud Server
Before deployment, confirm three things: how many messages the gateway will process each day, how many models it will call, and whether a vector database will be enabled. These numbers determine the server specifications.
A recommended starting configuration is 2 CPU cores, 4 GB of memory, and a 50 GB SSD system disk. This configuration is suitable for individuals or small teams and can support dozens of concurrent online sessions in scenarios based mainly on single-model calls. If multiple plugins will be loaded at the same time, or a vector database will run locally, upgrade to 4 cores and 8 GB of memory.
Choose the region based on data residency requirements and the model provider’s service regions. After selecting candidate nodes, use curl to test connectivity and latency to the target API:
curl -o /dev/null -s -w "HTTP %{http_code}, time %{time_total}s\n" https://api.example-provider.com/v1/models
After testing multiple times, choose a node with stable latency that also complies with your local regulations and the provider’s terms of service. If a model cannot be accessed directly from your network environment, use an access method officially supported by that provider, or switch to a model that can be accessed compliantly.
2. System Initialization and Access Control
Opening only the necessary entry points on the server is the step that requires the most careful attention during deployment.
1. Log in with an SSH key
Generate a key pair locally, then upload the public key to the server:
ssh-keygen -t ed25519 -C "gateway-admin"ssh-copy-id -i ~/.ssh/id_ed25519.pub ubuntu@your-server-ip
After confirming that key-based login works, modify /etc/ssh/sshd_config:
PasswordAuthentication noPermitRootLogin no
Run sudo systemctl restart sshd to apply the changes. Before making the change, keep the current terminal session open and open another window to test the new login method. Close the old session only after confirming the new method works, so you do not lock yourself out of the server.
2. Configure the host firewall
Using UFW as an example, allow SSH before enabling the firewall:
sudo ufw default deny incomingsudo ufw allow 22/tcpsudo ufw allow 443/tcpsudo ufw enable
The gateway container’s port 8080 should bind only to the local loopback address, with a reverse proxy providing external service. Do not expose it directly. PostgreSQL’s port 5432 and other internal service ports should also not be open to the public internet.
3. Configure the cloud platform security group
Security group rules should be consistent with the host firewall: limit port 22 to your own management IP, and open port 443 externally. If you plan to use Let’s Encrypt for automatic certificate issuance, you also need to temporarily open port 80.
3. Install the Container Runtime
Containerized deployment isolates dependencies and makes later upgrades and rollbacks easier. On Ubuntu, install it as follows:
sudo apt updatesudo apt install -y docker.io docker-compose-v2sudo systemctl enable --now dockersudo usermod -aG docker $USER
After running usermod, log out and back in for the user group change to take effect. After installation, check the versions:
docker --versiondocker compose version
If docker-compose-v2 is not available in your system sources, install Docker Engine and the Compose plugin according to the official Docker documentation. The commands later in this article use the v2 syntax docker compose with a space.
4. Get the Source Code and Prepare Directories
When obtaining the gateway source code, choose an explicit version tag instead of using latest directly. The content pointed to by latest changes over time, so the same configuration may produce different results when deployed at different times.
sudo mkdir -p /opt/ai-gatewaysudo chown $USER:$USER /opt/ai-gatewaygit clone <your chosen open-source gateway repository URL> /opt/ai-gatewaycd /opt/ai-gatewaygit checkout <stable version tag>mkdir -p data/postgres data/gateway
The directory structure is as follows:
/opt/ai-gateway├── docker-compose.yml├── .env└── data/├── postgres/└── gateway/
Read the project README to confirm how the image is built or where it is published, and record the full image name and version number.
5. Write Environment Variables and the Compose File
Keep sensitive information in the .env file rather than in docker-compose.yml. First generate random keys:
openssl rand -hex 24 # use as the database passwordopenssl rand -hex 32 # use as the gateway encryption key
Example .env:
POSTGRES_USER=gatewayPOSTGRES_PASSWORD=<database password generated above>POSTGRES_DB=gatewayGATEWAY_ENCRYPT_KEY=<encryption key generated above>
Set file permissions and confirm that .gitignore includes .env:
chmod 600 .env
docker-compose.yml defines both the database and the gateway services. The database does not map any ports, and the gateway accesses it through the service name postgres:
services:postgres:image: postgres:16-alpinerestart: unless-stoppedenvironment:POSTGRES_USER: ${POSTGRES_USER}POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}POSTGRES_DB: ${POSTGRES_DB}volumes:- ./data/postgres:/var/lib/postgresql/datanetworks:- internalhealthcheck:test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}"]interval: 10stimeout: 5sretries: 5ai-gateway:image: <your-gateway-image>:<version-tag>restart: unless-stoppedenvironment:DB_HOST: postgresDB_PORT: 5432DB_NAME: ${POSTGRES_DB}DB_USER: ${POSTGRES_USER}DB_PASSWORD: ${POSTGRES_PASSWORD}ENCRYPT_KEY: ${GATEWAY_ENCRYPT_KEY}ports:- "127.0.0.1:8080:8080"volumes:- ./data/gateway:/app/datadepends_on:postgres:condition: service_healthynetworks:- internalnetworks:internal:driver: bridge
There are three points to note here:
DB_HOSTmust match the service namepostgres.- Environment variable names such as
DB_HOSTandENCRYPT_KEYshould follow the documentation of the project you use; different projects may use different names. - Use
depends_ontogether withhealthcheckto ensure that the gateway starts only after the database is ready.
Start the services and check their status:
docker compose up -ddocker compose psdocker compose logs -f ai-gateway --tail 100
