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:

    1. 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:

    1. ssh-keygen -t ed25519 -C "gateway-admin"
    2. ssh-copy-id -i ~/.ssh/id_ed25519.pub ubuntu@your-server-ip

    After confirming that key-based login works, modify /etc/ssh/sshd_config:

    1. PasswordAuthentication no
    2. PermitRootLogin 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:

    1. sudo ufw default deny incoming
    2. sudo ufw allow 22/tcp
    3. sudo ufw allow 443/tcp
    4. sudo 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:

    1. sudo apt update
    2. sudo apt install -y docker.io docker-compose-v2
    3. sudo systemctl enable --now docker
    4. sudo 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:

    1. docker --version
    2. docker 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.

    1. sudo mkdir -p /opt/ai-gateway
    2. sudo chown $USER:$USER /opt/ai-gateway
    3. git clone <your chosen open-source gateway repository URL> /opt/ai-gateway
    4. cd /opt/ai-gateway
    5. git checkout <stable version tag>
    6. mkdir -p data/postgres data/gateway

    The directory structure is as follows:

    1. /opt/ai-gateway
    2. ├── docker-compose.yml
    3. ├── .env
    4. └── data/
    5. ├── postgres/
    6. └── 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:

    1. openssl rand -hex 24 # use as the database password
    2. openssl rand -hex 32 # use as the gateway encryption key

    Example .env:

    1. POSTGRES_USER=gateway
    2. POSTGRES_PASSWORD=<database password generated above>
    3. POSTGRES_DB=gateway
    4. GATEWAY_ENCRYPT_KEY=<encryption key generated above>

    Set file permissions and confirm that .gitignore includes .env:

    1. 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:

    1. services:
    2. postgres:
    3. image: postgres:16-alpine
    4. restart: unless-stopped
    5. environment:
    6. POSTGRES_USER: ${POSTGRES_USER}
    7. POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
    8. POSTGRES_DB: ${POSTGRES_DB}
    9. volumes:
    10. - ./data/postgres:/var/lib/postgresql/data
    11. networks:
    12. - internal
    13. healthcheck:
    14. test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}"]
    15. interval: 10s
    16. timeout: 5s
    17. retries: 5
    18. ai-gateway:
    19. image: <your-gateway-image>:<version-tag>
    20. restart: unless-stopped
    21. environment:
    22. DB_HOST: postgres
    23. DB_PORT: 5432
    24. DB_NAME: ${POSTGRES_DB}
    25. DB_USER: ${POSTGRES_USER}
    26. DB_PASSWORD: ${POSTGRES_PASSWORD}
    27. ENCRYPT_KEY: ${GATEWAY_ENCRYPT_KEY}
    28. ports:
    29. - "127.0.0.1:8080:8080"
    30. volumes:
    31. - ./data/gateway:/app/data
    32. depends_on:
    33. postgres:
    34. condition: service_healthy
    35. networks:
    36. - internal
    37. networks:
    38. internal:
    39. driver: bridge

    There are three points to note here:

    • DB_HOST must match the service name postgres.
    • Environment variable names such as DB_HOST and ENCRYPT_KEY should follow the documentation of the project you use; different projects may use different names.
    • Use depends_on together with healthcheck to ensure that the gateway starts only after the database is ready.

    Start the services and check their status:

    1. docker compose up -d
    2. docker compose ps
    3. docker compose logs -f ai-gateway --tail 100