OpenClaw

OpenClaw Gateway Architecture👨‍💻

What is OpenClaw Gateway?

The OpenClaw Gateway is the core runtime of the OpenClaw framework -- a self-hosted, open-source platform for building AI agents that communicate across chat platforms. The Gateway is the single process that powers every OpenClaw deployment, handling message routing, agent execution, session management, and channel integration in one unified service.

Unlike cloud-based agent platforms that lock you into a vendor's infrastructure, the OpenClaw Gateway runs entirely on your own hardware. You install it on a VPS, a Kubernetes cluster, a Raspberry Pi, or bare metal. Your data never leaves your servers, making it ideal for teams with strict privacy requirements, GDPR compliance needs, or simply a preference for full control over their AI stack.

The Gateway connects to 20+ chat platforms -- WhatsApp, Telegram, Discord, Slack, iMessage, Microsoft Teams, and more -- through a plugin-based channel adapter system. Each adapter normalizes incoming messages into a platform-agnostic format, so your agent code works identically regardless of where the user is chatting from. This means you write your agent logic once, and it automatically works across every connected channel.

At its heart, the Gateway is a message router. When a user sends a message on any connected platform, the Gateway receives it, evaluates the routing rules (called bindings), dispatches it to the appropriate AI agent, waits for the agent's response, and sends it back to the user on the originating platform. The entire pipeline -- from message receipt to response delivery -- typically completes in under 2 seconds.

Configuration is straightforward: a single JSON file at ~/.openclaw/openclaw.json defines everything -- the gateway port, channel connections, agent configurations, model providers, and routing rules. Secrets are handled via ${VAR_NAME} environment variable syntax, so credentials never need to be hardcoded.

Key Takeaways

  • 1The Gateway is a single Node.js process, not a distributed system. One process handles channel adapters, message routing, agent runtime, and session storage. This simplicity is intentional -- it makes deployment, debugging, and monitoring straightforward.
  • 2Messages flow through a clean pipeline: user sends on a chat platform, the Channel adapter normalizes the message, the Gateway routes it to the appropriate Agent, the Agent processes and responds, and the response flows back to the originating channel.
  • 3The Gateway is self-hosted by design. There is no SaaS version. You run it on your own hardware (VPS, Kubernetes, Raspberry Pi, bare metal), which gives you full data ownership and privacy compliance.
  • 4Configuration lives in a single JSON file at `~/.openclaw/openclaw.json`. This file defines the gateway port, channel connections, agent configurations, and routing rules. Environment variables are supported via `${VAR_NAME}` syntax for secrets.
  • 5The Gateway normalizes all messages into a platform-agnostic format. Your agent code never needs to know whether a message came from WhatsApp or Discord -- it receives the same structure regardless of the source channel.
  • 6OpenClaw requires Node.js 22 or higher. This is a hard requirement -- the Gateway uses modern Node.js features (native fetch, structuredClone, import assertions) that are not available in older versions.

Master openclaw gateway architecture

Take the OpenClaw Configuration & Binding course with hands-on lessons and challenges.

Examples

Installing and starting the Gateway

bash

The install script downloads the OpenClaw CLI. The onboard command runs an interactive wizard that configures authentication, gateway settings, and optional channels. The gateway command starts the process, which begins listening for messages from all configured channels. The default port is 18789.

Minimal gateway configuration file

json

This is a complete, working configuration. The gateway listens on port 18789, connects to Telegram and Discord via bot tokens stored in environment variables, and routes all messages to a default agent using Claude Sonnet. Tokens are never hardcoded -- the ${VAR_NAME} syntax references environment variables at runtime.

The normalized message format agents receive

json

Regardless of which platform a message originates from, the agent receives this normalized structure. The channel field identifies the source, but the agent logic remains platform-agnostic. This abstraction is what allows one agent to serve multiple chat platforms without any platform-specific code.

Running the Gateway as a background service with pm2

bash

For production deployments, wrap the Gateway in a process manager like pm2 so it restarts automatically on crashes and persists across system reboots. Running openclaw gateway directly in a terminal means it stops when the terminal closes -- pm2 prevents this.

Gateway message flow pipeline

bash

This shows the complete lifecycle of a message through the Gateway. Each step is handled by a different internal component (adapter, router, agent runtime), but they all run within the same process. The routing engine is the decision point that determines which agent handles each message.

Common Mistakes

Mistake:

Assuming OpenClaw is a hosted SaaS service and looking for a signup page or dashboard URL

Fix:

OpenClaw is self-hosted. You install it on your own machine or server and run the Gateway process yourself. There is no cloud-hosted version. This is by design for data ownership and privacy.

Mistake:

Running the Gateway on Node.js versions below 22, causing cryptic startup errors

Fix:

OpenClaw requires Node.js 22+. Always check your version with `node --version` before starting the Gateway. Use nvm or fnm to manage Node.js versions if needed.

Mistake:

Starting the Gateway directly in a terminal for production use, losing the process when the terminal closes

Fix:

Use a process manager like pm2, systemd, or Docker for production deployments. These ensure the Gateway restarts on crashes and persists across system reboots.

Mistake:

Hardcoding bot tokens and API keys directly in openclaw.json instead of using environment variables

Fix:

Always use the ${VAR_NAME} syntax in your configuration file to reference environment variables. Never commit tokens to version control. Use a secrets manager or .env file for local development.

Mistake:

Forgetting to open firewall ports for webhook-based channels like Telegram, causing messages to never reach the Gateway

Fix:

Channels that use webhooks need your server to be reachable on the configured port. Ensure your firewall, cloud security group, or reverse proxy allows inbound traffic on the Gateway port (default 18789).

Best Practices

  • Start with a single channel to validate your agent logic before adding more platforms. This reduces debugging surface area and lets you focus on getting the agent behavior right.
  • Place the Gateway behind a reverse proxy (Nginx, Caddy) for TLS termination, rate limiting, and domain routing. Never expose the raw Gateway port to the public internet.
  • Version-control your openclaw.json configuration. Treat it like code -- store it in Git, review changes in PRs, and use environment variables for anything that varies between environments.
  • Set up health checks and monitoring so you know immediately if the Gateway crashes or becomes unresponsive. The `openclaw gateway status` command is useful for scripted health checks.
  • Use the Control UI (`openclaw dashboard`) for real-time visibility into active sessions, connected channels, and agent activity. It runs on the same port as the Gateway.
  • Keep the Gateway updated. Run `openclaw update` regularly to get security patches, new channel adapters, and performance improvements.

Frequently Asked Questions

What is the OpenClaw Gateway?

The OpenClaw Gateway is a single Node.js 22+ process that acts as the runtime for the OpenClaw AI agent framework. It routes messages between chat platforms (WhatsApp, Telegram, Discord, Slack, and 20+ others) and the AI agents you configure. It handles channel adapters, message normalization, routing, agent execution, and session storage -- all in one self-hosted process.

Does OpenClaw Gateway require a cloud subscription?

No. The OpenClaw Gateway is fully self-hosted. There is no SaaS version or cloud subscription. You install and run it on your own infrastructure -- a VPS, Kubernetes, Docker, or bare metal. This gives you complete data ownership and privacy compliance.

What Node.js version does the Gateway require?

The OpenClaw Gateway requires Node.js 22 or higher. This is a hard requirement because the Gateway uses modern Node.js features like native fetch, structuredClone, and import assertions that are unavailable in older versions.

Can one Gateway handle multiple chat platforms simultaneously?

Yes. A single Gateway instance can connect to multiple chat platforms at the same time. Each platform uses a channel adapter that normalizes messages into a standard format, so your agents receive the same message structure regardless of the source platform.

How do I deploy the Gateway in production?

For production deployments, run the Gateway behind a reverse proxy (Nginx or Caddy) for TLS termination and use a process manager like pm2, systemd, or Docker to ensure automatic restarts. Never expose the raw Gateway port to the public internet. Store your configuration in version control and use environment variables for secrets.

Summary

The OpenClaw Gateway is a single Node.js 22+ process that routes messages between chat platforms and AI agents. It handles channel adapters, message normalization, routing, agent runtime, and session storage -- all in one process. Configuration lives in a single JSON file with environment variable support for secrets. For production, always use a process manager and reverse proxy. The Gateway's platform-agnostic message format means your agent code works identically across WhatsApp, Telegram, Discord, and 20+ other platforms.

Practice OpenClaw with hands-on challenges

Learn openclaw gateway architecture hands-on in your IDE

Interactive lessons and challenges on Stanza, practice in VS Code, Cursor, or the web.

Related Concepts

Related Cheatsheets

Master OpenClaw with Stanza

Interactive lessons and challenges, right in your code editor.

Check the free courses. No credit card.