Deploy an Open-Source AI Gateway on Ubuntu 24.04 and Connect It to LLM APIs
This tutorial explains how to deploy an open-source Node.js AI gateway on an Ubuntu 24.04 server and connect it to an OpenAI-compatible LLM API. It covers installing Node.js with nvm, installing the gateway via npm, troubleshooting common installation issues, configuring a custom provider and API key, accessing the web console through SSH port forwarding, and hardening the deployment for production.
1. Introduction and Solution Overview
As large language models become more widely available, many developers want to build a private AI service entry point on their own servers. Such a setup can unify access to LLM APIs from different providers while also providing a convenient web interface for chat and management. An open-source AI gateway tool built on Node.js addresses this need. It uses a “custom provider” design, allowing it to connect to any LLM service that follows the OpenAI-compatible API specification. This makes it a practical foundation for a private AI entry point.
This article uses an Ubuntu 24.04 server as an example and walks through the complete process: preparing the environment, installing the tool, connecting a model, and securing access. For consistency, the LLM service used in this article is referred to as “a mainstream LLM open platform.” Its API follows the commonly used OpenAI-compatible protocol: a unified /v4-style endpoint and authentication with an API key that begins with sk-. The same approach therefore also applies to other model services that provide compatible interfaces.
Before starting, prepare the following:
- A server running Ubuntu 24.04. Using a regular user with
sudoprivileges is recommended. For demonstration convenience, this article usesroot. - A valid LLM API key. Register on the target open platform and create one. Many platforms provide free allowances that are sufficient for personal testing.
- A local computer that can connect to the server over SSH. The operating system does not matter.
- A Node.js runtime. Installing the latest LTS version through a version manager is recommended.
2. Install the Node.js Runtime
This type of AI gateway tool is built on Node.js and has specific runtime version requirements. The Node.js version in the default Ubuntu 24.04 software repositories is often outdated and may not satisfy dependency requirements if installed directly. Using a Node version manager such as nvm is therefore recommended, as it makes switching and upgrading versions easier.
Run the following commands to install nvm and deploy Node.js 22 LTS:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bashsource ~/.bashrcnvm install 22nvm alias default 22node --version # Confirm output is v22.x.x
A few notes: First, the installation script automatically writes environment variables to the shell configuration file. You must run source or log in to the terminal again for the changes to take effect. Second, setting a default alias with alias default prevents the node command from becoming unavailable in a newly opened terminal. Third, if the server is in a network-restricted environment, you can configure a package mirror to speed up downloads.
3. Install the AI Gateway Tool
Once the environment is ready, install the open-source tool globally with npm:
npm install -g <tool-name>@latest
Two common issues may occur during installation. The first is deprecated dependency warnings. This is common in the npm ecosystem and only means that some indirect dependencies have released new versions. It does not affect the normal operation of the tool and can be safely ignored. The second is a directory conflict such as an ENOTEMPTY error. This is usually caused by a previous interrupted installation or version overwrite. To resolve it, remove the residual directory and cache, then reinstall:
rm -rf ~/.npm-global/lib/node_modules/<tool-name>npm cache clean --forcenpm install -g <tool-name>@latest
After installation, verify the version:
<tool-name> --version
A normal semantic version number indicates that the installation succeeded. If the command is not found, check whether npm’s global bin directory has been added to the PATH environment variable.
4. Connect an LLM API
The tool includes an interactive configuration wizard. Run the configuration command and follow the prompts to connect a model:
<tool-name> config
The key steps in the wizard are as follows:
- Select Add custom provider. This is the general entry point for connecting to any compatible API service.
- Give the provider an easy-to-identify name, such as
zhipuormy-model. - Enter the API endpoint address, which is the OpenAI-compatible base URL provided by the target LLM open platform. It usually looks like
https://<platform-domain>/api/paas/v4. - Paste the API key, which generally begins with
sk-. Make sure there are no spaces or line breaks before or after the key. - Select or enter the target model name. For example, choose a lightweight, high-speed model offered by the platform. It is suitable for daily chat scenarios and has relatively low call costs.
After configuration is complete, the wizard usually persists the information to a local configuration file. It is recommended to run the tool’s built-in status check command or start a test conversation to confirm that the key is valid, the network is reachable, and the model responds correctly. If an authentication error is returned, first check whether the key has expired and whether the account has available call quota. If a network timeout occurs, check the server’s outbound firewall policies and DNS resolution.
5. Access the Web UI Securely via SSH Port Forwarding
By default, the tool’s web console listens only on the server’s local loopback address (127.0.0.1). This is a security design choice that prevents the management interface from being directly exposed to the public internet. To access it from a local browser, use SSH port forwarding (local forwarding) to establish an encrypted tunnel:
ssh -L 8080:127.0.0.1:8080 <username>@<server-ip>
This command forwards traffic from local port 8080 through the encrypted SSH channel to port 8080 on the server’s local loopback interface. Keep this SSH session open, then visit http://127.0.0.1:8080 in your local browser to open the web console. The actual port number should match the tool’s default configuration or your custom setting.
Compared with directly opening a firewall port, SSH forwarding has natural advantages: all traffic is encrypted, and it reuses SSH’s authentication system, so there is no need to maintain a separate set of access credentials. For long-term use, you can combine SSH key login with a ~/.ssh/config configuration to simplify the connection command.
6. Production Hardening Recommendations
If you plan to use this service in a more formal production environment, consider adding the following hardening measures:
- Run the service as a regular user instead of
rootto avoid the security risks associated with root privileges. - Create a systemd service unit to enable startup on boot and automatic restart after failures.
- Store API keys securely. Avoid writing them into code repositories or public logs, and use environment variable injection when necessary.
- Use firewall policies to restrict SSH access by source IP and reduce the risk of brute-force attacks.
- Monitor LLM API usage and costs. Set quota alerts on the platform side to prevent unexpected consumption.
- Regularly update the tool version and Node.js runtime to receive security fixes in a timely manner.
7. Conclusion
This article demonstrated the complete process of deploying an open-source AI gateway tool on Ubuntu 24.04 and connecting it to an LLM API compatible with the OpenAI protocol. It covered installing a Node.js LTS environment with nvm, installing the tool globally and handling common errors, completing model configuration with an interactive wizard, and using SSH port forwarding to enable secure local access. The solution does not depend on a specific vendor and offers good portability. Developers can replace the model provider as needed and build their own private AI service entry point.
