Deploy an Open-Source AI Gateway on Ubuntu 24.04: A Practical Guide

    This guide walks through deploying an open-source AI gateway on Ubuntu 24.04, covering the three-layer architecture, Node.js runtime setup with a version manager, gateway installation and troubleshooting, custom model provider configuration, and secure remote access via SSH port forwarding. You will learn how to build a unified, self-hosted entry point for external LLM APIs without exposing your service to the public internet.

    1. Requirements and Architecture Overview

    As large language models mature, more developers want a unified AI interaction entry point on their own servers. Exposing a web service port directly carries significant security risks, so this guide uses a “local runtime + remote forwarding” deployment model. The architecture has three layers:

    • Bottom layer: Ubuntu 24.04 and the Node.js runtime.
    • Middle layer: The open-source AI gateway, which handles session management and interface adaptation.
    • Top layer: Remote LLM providers, which serve inference requests over standard HTTP.

    The core benefit of this design is decoupling. The gateway does not host model weights; it acts only as middleware for request routing and UI rendering, so hardware requirements are modest—a standard 2-core, 4 GB cloud host is enough. Model capabilities come from external APIs, letting you switch providers by task type and avoid vendor lock-in.

    2. Prerequisites and Resource Preparation

    Before you start, make sure you have:

    • A server running Ubuntu 24.04. This guide uses the root account for demonstration; in production, create a regular user with sudo privileges.
    • A local terminal tool on Windows, macOS, or Linux with SSH support.
    • A console account on an LLM platform to create an API key prefixed with sk-. A free personal quota is usually enough for debugging.
    • A stable network egress so the server can reach external API endpoints.

    Note that the Node.js version in the default Ubuntu 24.04 repositories is relatively conservative, while modern frontend toolchains have hard runtime version requirements. We therefore install it through a version manager.

    3. Setting Up the Node.js Runtime

    A version manager lets you switch versions at any time and avoids polluting system-wide directories. Run the following commands to install and initialize it:

    1. # Download and run the version manager install script
    2. curl -o- https://<version-manager-official-url>/install.sh | bash
    3. source ~/.bashrc
    4. # Install the LTS version and set it as default
    5. nvm install 22
    6. nvm alias default 22
    7. node --version # expected output: v22.x.x
    8. npm --version

    If curl is missing, install it first with the system package manager. After installation, npm’s global directory points to user space, which prevents the permission conflicts that commonly occur later.

    4. Installing the AI Gateway and Handling Errors

    Once the runtime is ready, install the gateway globally:

    1. npm install -g <gateway-package-name>@latest

    Three typical issues may arise during installation:

    1. Directory not empty error. This usually comes from leftover files after an interrupted install. Locate the global modules directory, remove the leftover subdirectory, clear the cache, and retry:

    1. rm -rf ~/.npm-global/lib/node_modules/<gateway-package-name>
    2. npm cache clean --force
    3. npm install -g <gateway-package-name>@latest

    2. Deprecation warnings. Some low-level packages in the dependency tree marked as deprecated are a normal part of ecosystem evolution. You can continue as long as the main program reports no errors.

    3. Network timeouts. Configuring a mirror source can improve download success rates. After installation, verify with a version query command; the expected output looks like 2026.3.2.

    5. Configuring a Custom Model Provider

    The gateway provides an interactive wizard that reduces the chance of errors from hand-writing configuration files:

    1. openclaw config

    The key steps are:

    • Choose to add a custom provider.
    • Enter a recognizable name, for example zhipu.
    • Enter the OpenAI-compatible API base URL, typically https://<platform-url>/api/paas/v4.
    • Paste the API key you created earlier.
    • Add the specific model identifier in the model list and set inference parameters such as context length and temperature.

    Most domestic model services offer endpoints compatible with the standard format, so the gateway does not need a dedicated adapter for each vendor. If a call returns an authentication failure, first check the key for extra whitespace. If it returns a model-not-found error, verify that the model identifier’s capitalization matches the provider’s documentation.

    6. Accessing the UI Securely via SSH Port Forwarding

    The gateway listens on the loopback address by default and is not directly reachable from outside—this is part of the security design. On your local machine, run:

    1. ssh -L 8080:127.0.0.1:8080 root@<server-ip>

    After the tunnel is established, open the corresponding port in your local browser to use the full web interface. Compared with opening a firewall port, this approach has three benefits: the service is not exposed to the public internet, traffic is encrypted by SSH, and access control reuses the system account system. For long-running background operation, you can manage the gateway process with a process supervisor or a systemd service unit, and add log services and monitoring alerts for observability.

    7. Summary

    This guide covers a complete path from zero to a working setup: runtime preparation, installation and troubleshooting, model provider integration, and secure remote access. Once you master this methodology, you can follow the same deployment pattern to connect general-purpose model capabilities from platforms such as Baidu AI Cloud’s Qianfan, or any other inference service that is compatible with standard protocols, and quickly build your own AI workspace.