OpenClaw Gateway Explained: Commands, Ports, Auth, and Common Fixes

Werlist99

 


OpenClaw Gateway — Practical Guide (Polished Draft)

1. What Is the Gateway? (One-Minute Primer)

If you searched for “openclaw gateway” or “openclaw gateway start,” you probably installed OpenClaw but are not sure what the Gateway does. In short: the Gateway is OpenClaw’s control plane. It receives messages from chat platforms (Telegram, LINE, Discord, and others), routes them to AI agents, and manages connections and authentication.

MIT Technology Review described AI agents in early 2025 as systems that can autonomously carry out multi-step tasks. OpenClaw’s Gateway is the infrastructure that makes that autonomy usable: without it, agents cannot reliably receive instructions, connect to external services, or run in a stable way. The orchestration layer—in OpenClaw, that is the Gateway—is what turns a standalone model into something that behaves like an agent.

Think of it as a switchboard: every inbound message goes through the Gateway first; it decides which agent handles the work, which model to use, and which security rules apply.


2. Gateway CLI — Quick Reference

These commands cover the vast majority of day-to-day Gateway management (per OpenClaw docs).

2.1 Status

CommandPurpose
openclaw gateway status
Running/stopped, port, PID
openclaw gateway status --json
Machine-readable output
openclaw gateway status --deep
Deeper check (e.g. WebSocket, channels)
openclaw status
Gateway + node + channels overview
openclaw status --deep
Full diagnostics
openclaw health
Quick “is the Gateway responding?” check

2.2 Start / stop / service

CommandPurpose
openclaw gateway --port 18789
Run in foreground (default port 18789); Ctrl+C stops
openclaw gateway install --force
Install/reinstall background service (systemd on Linux, launchd on macOS)
openclaw gateway restart
Restart the Gateway service (common after config changes)

Note: There are no separate gateway start / gateway stop subcommands. To run interactively, use openclaw gateway. For a service, use openclaw gateway install --force. To stop the service, use OS tools (e.g. systemctl stop openclaw-gateway on Linux, or launchctl unload on macOS as appropriate).

2.3 Diagnostics & security

CommandPurpose
openclaw doctor
Config, permissions, connectivity checks
openclaw doctor --generate-gateway-token
Generate token; can write into config
openclaw logs --follow
Stream logs (like tail -f)
openclaw security audit
Security scan
openclaw security audit --deep
Deeper scan (auth, tokens, exposure)
openclaw security audit --fix
Attempt automatic fixes

2.4 Configuration

CommandExample
openclaw config get <key>
openclaw config get gateway.port
openclaw config set <key> <value>
openclaw config set gateway.port 28789
openclaw config unset <key>
e.g. remove gateway.auth.token
openclaw configure
Interactive wizard
openclaw onboard --install-daemon
Full setup path (auth, gateway, channels, daemon)

3. Port Configuration (Most Common Startup Issues)

3.1 Default: 18789

The Gateway’s default WebSocket port is 18789. After install, the Control UI is usually at http://127.0.0.1:18789.

3.2 Change the port

CLI (recommended)

openclaw config set gateway.port 28789
openclaw config get gateway.port
openclaw gateway restart

Edit config — typically ~/.openclaw/openclaw.json (JSON5):

{
gateway: {
port: 28789,
bind: "loopback"
}
}

Temporary override (no persistent config change)

openclaw gateway --port 28789

3.3 EADDRINUSE (port already in use)

# macOS / Linux
sudo lsof -i :18789
kill -9 <PID>

Or pick another port via openclaw config set gateway.port … and restart.


4. Token & Authentication

Treat Gateway tokens like full-privilege operator credentials. Prefer strong auth, least exposure, and secrets via environment variables—not plaintext in config when avoidable.

4.1 Generate / set / verify

openclaw doctor --generate-gateway-token
openclaw config set gateway.auth.token "your-long-random-token"
openclaw config get gateway.auth.token

4.2 Auth modes (typical)

ModeConfigWhen to use
Token
gateway.auth.mode: "token"
Default recommendation for many setups
Password
gateway.auth.mode: "password"
Often paired with OPENCLAW_GATEWAY_PASSWORD
Trusted proxy
gateway.auth.mode: "trusted-proxy"
Behind Nginx/Caddy with trusted identity headers

Example (token via env):

{
gateway: {
auth: {
mode: "token",
token: "${OPENCLAW_GATEWAY_TOKEN}"
}
}
}

4.3 Environment files (priority)

Common pattern: ~/.openclaw/.env

OPENCLAW_GATEWAY_TOKEN=...
OPENCLAW_GATEWAY_PASSWORD=...

Typical precedence: parent process env → .env in cwd → ~/.openclaw/.env.


5. Local vs Remote (Source of Many “Start Blocked” Errors)

5.1 Local (default)

Gateway accepts localhost traffic; common for dev/single machine:

openclaw config set gateway.mode local
openclaw config set gateway.bind loopback

5.2 Remote

Allows other devices on the network to connect. Usually requires auth before non-loopback bind—follow official docs for your version:

openclaw config set gateway.mode remote
openclaw doctor --generate-gateway-token
openclaw config set gateway.bind 0.0.0.0
openclaw gateway restart

Warning: 0.0.0.0 increases reachability; combine with firewall rules, VPN (e.g. Tailscale), or reverse proxy patterns as recommended.

5.3 SSH tunnel (often the safest remote-access pattern)

ssh -N -L 18789:127.0.0.1:18789 user@your-server

Gateway can stay on loopback; you access it locally via the tunnel.


6. Common Errors → Likely Fix

SymptomLikely causeFix
Gateway start blocked (local-related)
Mode/bind mismatch
Set gateway.mode / gateway.bind per docs
Refusing to bind without auth
Non-loopback without proper auth
Configure token/password/trusted proxy
EADDRINUSE
Another process or duplicate Gateway
Free the port or change gateway.port
Service missing
Daemon not installed
openclaw gateway install --force
AUTH_TOKEN_MISMATCH
Wrong/expired token
Regenerate / align client & server token
Runtime: stopped
Crash or exit
openclaw logs --follow + openclaw doctor

Standard triage order: openclaw gateway status  openclaw logs --follow  openclaw doctor.


7. Example openclaw.json (Gateway-focused)

{
gateway: {
mode: "local",
port: 18789,
bind: "loopback",
auth: {
mode: "token",
token: "${OPENCLAW_GATEWAY_TOKEN}"
},
reload: {
mode: "hybrid"
},
remote: {
url: "ws://127.0.0.1:18789",
token: "remote-token"
}
}
}

Adjust remote when this machine is a client to another Gateway.


8. Linux: systemd (typical)

openclaw gateway install --force
systemctl status openclaw-gateway
systemctl restart openclaw-gateway
journalctl -u openclaw-gateway -f

9. Security Checklist (Before You Expose Anything)

CheckCommand / actionGoal
Auth mode
openclaw config get gateway.auth.mode
Not “open by accident”
Bind
openclaw config get gateway.bind
Avoid public bind unless intended
Config perms
ls -la ~/.openclaw/openclaw.json
Restrictive permissions
Dir perms
ls -ld ~/.openclaw/
Restrictive permissions
Audit
openclaw security audit --deep
No critical findings
Logs
openclaw config get logging.redactSensitive
Reduce sensitive leakage

FAQ (Short)

  • Default port? 18789 — UI often at http://127.0.0.1:18789.
  • “Gateway start blocked”? Align gateway.mode / auth / bind with what remote access requires; see official error text for your build.
  • Phone control safely? Prefer SSH tunnel or VPN; avoid raw public exposure.
  • Forgot token? openclaw config get gateway.auth.token or regenerate with openclaw doctor --generate-gateway-token.
  • Multiple machines? Generally one Gateway per host/process design; avoid port conflicts and duplicate services. 
OpenClaw Gateway CLI WebSocket Localhost Security Token Troubleshooting Linux Self-hosted AI
Table of Contents

Post a Comment