Skip to main content

REST Endpoints

The OpenClaw Gateway provides HTTP REST endpoints for specific use cases including OpenAI compatibility, webhooks, and tool invocation.

OpenAI-Compatible Chat Completions

POST /v1/chat/completions

OpenAI-compatible chat completions endpoint. Authentication:
Authorization: Bearer your-token-here
Request Body:
model
string
required
Model identifier (e.g., "openclaw", "gpt-4"). Maps to OpenClaw agent.
messages
array
required
Array of message objects with role and content
stream
boolean
default:false
Enable streaming responses (SSE)
user
string
User identifier for session scoping
Response:
id
string
Completion ID (format: chatcmpl_<uuid>)
object
string
"chat.completion" or "chat.completion.chunk" (for streaming)
created
number
Unix timestamp
model
string
Model identifier from request
choices
array
Array of completion choices
usage
object
Token usage statistics
Example (Non-Streaming):
curl -X POST http://localhost:18789/v1/chat/completions \
  -H "Authorization: Bearer your-token" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "openclaw",
    "messages": [
      {"role": "system", "content": "You are a helpful assistant."},
      {"role": "user", "content": "What is OpenClaw?"}
    ]
  }'
Response:
{
  "id": "chatcmpl_123e4567-e89b-12d3-a456-426614174000",
  "object": "chat.completion",
  "created": 1234567890,
  "model": "openclaw",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "OpenClaw is an open-source AI agent framework..."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 0,
    "completion_tokens": 0,
    "total_tokens": 0
  }
}
Example (Streaming):
curl -X POST http://localhost:18789/v1/chat/completions \
  -H "Authorization: Bearer your-token" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "openclaw",
    "messages": [{"role": "user", "content": "Hello"}],
    "stream": true
  }'
Streaming Response (SSE):
data: {"id":"chatcmpl_123","object":"chat.completion.chunk","created":1234567890,"model":"openclaw","choices":[{"index":0,"delta":{"role":"assistant"}}]}

data: {"id":"chatcmpl_123","object":"chat.completion.chunk","created":1234567890,"model":"openclaw","choices":[{"index":0,"delta":{"content":"Hello"}}]}

data: [DONE]

Webhook Endpoints (Hooks)

POST /hooks/:path

Custom webhook endpoints for external integrations. Configuration:
hooks:
  enabled: true
  token: "your-hook-token"
  path: "/hooks"
  maxBodyBytes: 262144
Authentication:
Authorization: Bearer your-hook-token
Or:
X-OpenClaw-Token: your-hook-token
Wake Endpoint:
POST /hooks/wake
Content-Type: application/json

{
  "text": "Wake up message",
  "mode": "now"  // or "next-heartbeat"
}
Agent Endpoint:
POST /hooks/agent
Content-Type: application/json

{
  "message": "User message",
  "agentId": "default",
  "sessionKey": "hook:session-123",
  "name": "Webhook User",
  "deliver": true,
  "channel": "signal",
  "to": "+1234567890",
  "model": "gpt-4",
  "thinking": "high",
  "wakeMode": "now",
  "timeoutSeconds": 300
}
message
string
required
User message to send to agent
agentId
string
Target agent ID (defaults to configured default)
sessionKey
string
Session key for conversation context
name
string
Display name for the sender
deliver
boolean
default:true
Whether to deliver response via channel
channel
string
Channel to deliver response (e.g., "signal", "telegram", "discord")
to
string
Recipient identifier (phone number, user ID, etc.)
model
string
Override model for this request
thinking
string
Thinking budget: "low", "medium", "high"
wakeMode
string
default:"now"
"now" or "next-heartbeat"
timeoutSeconds
number
Request timeout in seconds
Response:
{
  "ok": true,
  "runId": "unique-run-id"
}
Custom Mappings: You can define custom webhook mappings:
hooks:
  mappings:
    - path: "github"
      action:
        kind: "agent"
        message: "{{ payload.commits[0].message }}"
        channel: "discord"
        to: "#dev-notifications"
See Hooks for details.

Tool Invocation

POST /api/tools/invoke

HTTP-based tool invocation endpoint. Authentication:
Authorization: Bearer your-token
Request Body:
tool
string
required
Tool name to invoke
params
object
Tool-specific parameters
Example:
curl -X POST http://localhost:18789/api/tools/invoke \
  -H "Authorization: Bearer your-token" \
  -H "Content-Type: application/json" \
  -d '{
    "tool": "weather",
    "params": {
      "location": "San Francisco"
    }
  }'
Response:
{
  "ok": true,
  "result": {
    "temperature": 68,
    "conditions": "Partly cloudy"
  }
}

Channel Endpoints

POST /api/slack/events

Slack Events API endpoint for receiving Slack app events. Authentication: Handled via Slack signing secret verification. Request Body: Slack event payload (see Slack Events API). Response:
{
  "ok": true
}
See Slack Integration for setup.

/api/channels/:channelId/*

Channel-specific HTTP endpoints exposed by channel plugins. Authentication:
Authorization: Bearer your-token
Examples:
  • /api/channels/telegram/webhook - Telegram webhook
  • /api/channels/discord/interactions - Discord interactions
Channel endpoints are dynamically registered by plugins. See individual channel documentation.

Health Check

GET /health

Health check endpoint (no authentication required). Response:
{
  "ok": true,
  "status": "healthy"
}

Error Responses

All REST endpoints return standard error responses: 400 Bad Request:
{
  "error": {
    "message": "Invalid request body",
    "type": "invalid_request_error"
  }
}
401 Unauthorized:
{
  "error": {
    "message": "Unauthorized",
    "type": "authentication_error"
  }
}
429 Too Many Requests:
{
  "error": {
    "message": "Too many failed authentication attempts. Please try again later.",
    "type": "rate_limited"
  }
}
500 Internal Server Error:
{
  "error": {
    "message": "Internal error",
    "type": "api_error"
  }
}

Next Steps

Hooks

Configure webhook integrations

OpenAI Compatibility

Use OpenAI-compatible API