Self-Hosted AI Assistant Gateway: Deployment and Troubleshooting Guide
This guide explains how to deploy and operate an OpenClaw-style AI assistant gateway that provides a unified entry point for multiple model providers and can be accessed through a web interface or enterprise messaging platform. It covers environment checks, installation, configuration, validation, bot integration, troubleshooting, workspace isolation, and secure skill development. Commands and configuration fields may vary by version, so verify them with `--help` and the official documentation.
Self-Hosted AI Assistant Gateway: Deployment and Troubleshooting Guide
Many teams want to connect capabilities from multiple model providers through a single entry point, allowing employees to use AI through a web interface or an enterprise messaging platform. This guide uses an OpenClaw-style AI assistant gateway as an example and covers the process from environment checks to production operations.
Commands and field names may vary by version. When they do not match your installation, run --help first or consult the documentation for that version.
1. Environment Preparation
Runtime version
The gateway runs on Node.js. Node.js 18 LTS or a later LTS release is recommended. Verify the installed versions with:
node -vnpm -v
Hardware resources
A test environment with 512 MB of memory may be enough to start the gateway, but the process can be terminated by the operating system as the number of sessions increases.
For individual users or small teams, 1 CPU core, 2 GB of memory, and 5 GB of available disk space are recommended. If the gateway needs to support concurrent conversations for more than a dozen users, size the memory according to the expected concurrency and monitor peak usage.
Network connectivity
The server must be able to reach the API endpoint of every model provider you connect. Use the following command to test the network layer:
curl -I https://your-model-provider-api-endpoint
Any HTTP status code, including 401, indicates that the server can reach the endpoint at the network level.
If the server is located on a private network, configure a proxy first and make sure the proxy variables are available in the gateway service environment.
Port availability
Confirm that the planned port is available. The examples below use port 8080:
# Linux / macOSlsof -i :8080# Windowsnetstat -ano | findstr 8080
2. Installation and Initialization
Option 1: Install globally with npm
This is the most direct approach and is suitable for most deployments:
npm install -g openclawopenclaw --version
If the version is displayed successfully, the installation is complete.
If you encounter a permission error, do not install directly with sudo. Configure npm’s global installation directory instead to avoid permission problems during future upgrades.
Option 2: Build from source
Building from source is suitable for teams that need to customize the project. Clone the code from the project’s official repository, whose address is available in its README, and run:
npm installnpm run buildnpm link
Run the initialization wizard
Start the wizard and provide the model API key, gateway port, access token, and bot credentials when prompted:
openclaw init
The wizard generates a configuration file. If it does not display the file path, look for a file named openclaw.json in the project directory.
At minimum, the configuration must include a model provider API endpoint and key, along with the gateway listening port.
3. Configuration and Validation
Recommended configuration structure
The following template separates model, gateway, session, and messaging-bot settings. Secrets are injected through environment variables rather than stored directly in the configuration file:
{"models": {"default": "chat-main","providers": [{"name": "chat-main","baseUrl": "https://api.example-provider.com/v1","apiKey": "${MODEL_API_KEY}","defaultModel": "your-chat-model","timeoutMs": 60000,"retries": 2}]},"gateway": {"host": "127.0.0.1","port": 8080,"authToken": "${GATEWAY_TOKEN}","logLevel": "info"},"session": {"store": "file","path": "./data/sessions"},"im": {"enabled": false,"appId": "${IM_APP_ID}","appSecret": "${IM_APP_SECRET}","callbackPath": "/im/callback"}}
The domain, model name, and field names in this template are examples. Replace them with the values used in your environment and follow the field definitions for your installed version.
Inject secrets
Store secrets in a separate file, restrict its permissions, and do not commit it to a code repository:
mkdir -p ~/.secrets && chmod 700 ~/.secretsprintf '%s' 'your-model-api-key' > ~/.secrets/model_keychmod 600 ~/.secrets/model_keyexport MODEL_API_KEY="$(cat ~/.secrets/model_key)"
Validate the configuration format
Check the JSON syntax before starting the service. Many startup failures are caused by malformed configuration files:
python3 -m json.tool openclaw.json > /dev/null && echo "Valid JSON"
Start and verify the service
Use openclaw start as an example, but follow the command shown by openclaw --help for your version.
After startup, verify the service in three steps.
Check the process and logs for errors:
tail -n 100 ./logs/gateway.log
Call the health-check endpoint. A
200response indicates that the service is reachable. If access-token authentication is enabled, include the authorization header:curl -i -H "Authorization: Bearer $GATEWAY_TOKEN" http://127.0.0.1:8080/health
Start a real conversation through the web interface or command line to confirm that the complete model invocation path works.
Integrate a messaging bot
Event callbacks from an enterprise messaging platform must be reachable from the public internet. Use an HTTPS domain and a reverse proxy to forward requests to the gateway callback path.
Tunneling tools are suitable only for temporary testing. After the integration is configured, send a test message to the bot and monitor the gateway logs to confirm that the event is received and a response is sent.
Expose the service safely
By default, the gateway listens only on the local host. When the service must be made publicly available, expose only the reverse proxy’s HTTPS port, keep the gateway port private, and enable access-token authentication.
4. Operations and Troubleshooting
Use the following checklist to investigate common problems. Start with the checks in the second column and then apply the corresponding remedy.
| Symptom | First check | Recommended action |
|---|---|---|
Model requests return 401 |
Whether the key is available in the service environment | Run echo ${#MODEL_API_KEY} to check the key length without printing the secret |
Model requests return 429 or indicate insufficient quota |
Usage and quota in the provider console | Increase the quota or configure a backup provider for the default model |
| Requests time out | Connectivity from the server to the model API | Run curl -I again and increase timeoutMs if necessary |
Startup reports EADDRINUSE |
Whether the port is already occupied | Run lsof -i :8080 to identify the process or change gateway.port |
| The process exits immediately | Configuration-file syntax | Run python3 -m json.tool openclaw.json |
| The bot does not respond | Whether the callback URL is reachable | Run curl -i -X POST https://your-domain.example/im/callback; a 5xx response indicates a gateway or proxy problem |
| The bot receives no events | Whether event subscriptions are enabled on the platform | Check the subscribed events and callback URL in the messaging platform’s developer console |
| Conversation context is lost after restart | Session storage configuration | Change session.store from in-memory storage to file and verify directory write permissions |
During troubleshooting, you can temporarily change gateway.logLevel to debug. Debug logs may contain users’ conversation content. After the issue is resolved, change the level back to info and remove the relevant log files.
5. Workspaces and Skill Extensions
Workspaces
Workspaces organize sessions, members, models, and tools. A single deployment can contain multiple workspaces, each with its own system prompt and tool allowlist.
For example, a development workspace can be allowed to read code files, while an operations workspace provides only copywriting capabilities:
{"workspaces": [{"name": "dev-assistant","model": "chat-main","tools": ["file-read"],"members": ["team-dev"]},{"name": "ops-copywriter","model": "chat-main","tools": [],"members": ["team-ops"]}]}
Follow two rules when assigning workspaces:
- Add members only to the workspace for their own team.
- Do not grant new tools by default. Enable them individually only when required.
Skill plugins
Skills define a name, description, and parameters declaratively, along with an execution function. The following is a minimal read-only file skill.
It restricts access to the workspace directory, prevents path traversal, and limits the file size:
const path = require("node:path");const fs = require("node:fs/promises");const ROOT = path.resolve(process.env.WORKSPACE_ROOT ?? "./workspace");const MAX_BYTES = 1024 * 1024;module.exports = {name: "file-read",description: "Read a text file within the workspace",parameters: {path: { type: "string", description: "File path relative to the workspace root" },},async execute({ path: relPath }) {if (typeof relPath !== "string" || relPath.length > 256) {throw new Error("Invalid path parameter");}const target = path.resolve(ROOT, relPath);if (target !== ROOT && !target.startsWith(ROOT + path.sep)) {throw new Error("Path is outside the workspace");}const stat = await fs.stat(target);if (!stat.isFile() || stat.size > MAX_BYTES) {throw new Error("File does not exist or exceeds 1 MB");}return fs.readFile(target, "utf8");},};
Keep three principles in mind when developing skills:
- Validate the type and range of every parameter before execution.
- High-risk operations, including writing, deleting, or sending external messages, must require human confirmation and must not be triggered directly by the model.
- Request only the minimum permissions needed to complete the task. For example, grant access to a read-only directory rather than the entire disk.
