Skip to main content

Gateway API Overview

The OpenClaw Gateway API provides programmatic access to agent interactions, session management, and real-time communication via WebSocket and REST endpoints.

Base URL

The Gateway API runs on your local or remote OpenClaw instance:
The default port is 18789. You can configure this in your OpenClaw config:

API Transport

OpenClaw Gateway supports two transport mechanisms:
  • WebSocket - Primary protocol for real-time bidirectional communication
  • HTTP/REST - Alternative endpoints for specific use cases (OpenAI compatibility, hooks, tools)

Authentication

All API requests require authentication. See Authentication for details. Quick example:

Rate Limits

The Gateway implements rate limiting for authentication attempts to prevent brute-force attacks:
  • Limit: 20 failed authentication attempts per client
  • Window: 60 seconds
  • Response: 429 Too Many Requests with Retry-After header

Available Endpoints

WebSocket Protocol

  • Gateway WebSocket: ws://localhost:18789/ - Primary RPC protocol
  • Canvas WebSocket: ws://localhost:18789/canvas/ws - Canvas host communication
See WebSocket Protocol for details.

REST Endpoints

  • OpenAI Compatibility: /v1/chat/completions - OpenAI-compatible chat endpoint
  • Hooks: /hooks/* - Webhook endpoints for external integrations
  • Tools Invoke: /api/tools/invoke - HTTP-based tool invocation
  • Slack Events: /api/slack/events - Slack app event receiver
  • Channels: /api/channels/* - Channel-specific HTTP endpoints
See REST Endpoints for details.

Response Format

WebSocket Responses

WebSocket responses follow the RPC frame format:

HTTP Responses

HTTP endpoints return standard JSON:
Error responses:

Error Codes

Common error codes:

WebSocket vs REST

Use WebSocket when:
  • You need real-time bidirectional communication
  • Subscribing to events (agent responses, presence, health)
  • Invoking multiple RPC methods
  • Building interactive clients (CLI, mobile apps, web UI)
Use REST when:
  • Integrating with external systems via webhooks
  • OpenAI-compatible API access
  • Simple one-off requests
  • Tool invocation from HTTP-based systems

Next Steps

Authentication

Learn about authentication methods

WebSocket Protocol

Connect via WebSocket

REST Endpoints

Use HTTP endpoints

Agent Protocol

Invoke agents via API