4766. All endpoints require authentication unless noted otherwise.
The gateway is implemented with Hono and lives in
packages/gateway/src/server/hono-server.ts. Companion routes are wired in
packages/daemon/src/wiring/setup-gateway-routes.ts (experimental /v1
routes, media, and webhook mappings).
Authentication
The gateway supports four authentication methods depending on the endpoint type.Bearer Token
The primary authentication method. Pass a token configured ingateway.tokens[] via the Authorization header.
WebSocket Query Parameter
WebSocket clients that cannot set custom headers may pass the token as a query parameter. SSE endpoints require theAuthorization header and reject ?token= credentials.
HMAC Signature
The webhook endpoint (/hooks/webhook) authenticates requests using an HMAC signature. The signature is computed over the request body and verified against a shared secret. The HMAC algorithm is configurable (defaults to SHA-256).
mTLS
Optional TLS client certificate verification. Whengateway.tls.requireClientCert is true, the server requires clients to present a valid certificate signed by the configured CA.
Rate Limiting
The gateway applies rate limiting at multiple levels to protect against abuse.- Global HTTP rate limiter applies to all HTTP endpoints except
/healthand/api/health. Configured viagateway.rateLimit. - Per-connection WebSocket rate limiting uses a sliding window to limit messages per connection. Configured via
gateway.wsMessageRateLimit.maxMessagesandgateway.wsMessageRateLimit.windowMs. - Body size limit on POST endpoints (default: 1 MB). Configured via
gateway.httpBodyLimitBytes.
For detailed rate limiting configuration, see Rate Limiting.
Core Routes
These routes are always available when the gateway is running.REST API
The REST API is mounted at/api and provides HTTP endpoints for the web dashboard. These endpoints are available when gateway.web.enabled is true (the default).
REST API endpoints are available when the web dashboard is enabled. All authenticated REST API endpoints require at least the
rpc scope.POST /api/chat
Execute an agent turn with the following request body.SSE Endpoints
Server-Sent Events (SSE) endpoints provide real-time streaming. Both endpoints require anAuthorization: Bearer ... header and at least the rpc scope. Query-string credentials are
rejected so tokens never need to enter a URL. A narrowly-scoped mcp-client token is rejected
with 403 because the event stream carries cross-session data and can drive agent turns.
SSE Connection Lifecycle
The/api/events endpoint streams system events as they occur. The server sends periodic keep-alive pings (every 15 seconds) to maintain the connection. If the connection drops, clients should reconnect using the retry directive (default: 3 seconds).
Event types are organized by category:
Messages: message:received, message:sent, message:streaming
Sessions: session:created, session:expired, session:sub_agent_spawned, session:sub_agent_completed, session:sub_agent_archived, session:sub_agent_spawn_rejected, session:sub_agent_spawn_started, session:sub_agent_spawn_queued, session:sub_agent_lifecycle_ended
Security: audit:event, security:injection_detected, security:injection_rate_exceeded, security:memory_tainted, security:warn, secret:accessed, secret:modified
Skills: skill:executed, skill:rejected, skill:loaded, skill:registry_reset
Observability: observability:metrics, observability:token_usage, observability:reset
Scheduler: scheduler:cron_execution_started, scheduler:cron_execution_terminal, scheduler:heartbeat_wake_admitted, scheduler:heartbeat_wake_deferred, scheduler:heartbeat_wake_terminal, scheduler:heartbeat_alert
The three heartbeat wake events share a correlationId. Admission reports the retained target, lane, reason, and disposition; deferral adds the next eligible time and a closed reason; terminal reports the final status, duration, event-entry count, and optional error or cancellation category. scheduler:heartbeat_alert is a separate health signal and is not part of the correlated wake lifecycle.
Approvals: approval:requested, approval:resolved
Graphs: graph:started, graph:node_updated, graph:completed
Config: config:patched
Diagnostics: diagnostic:channel_health, diagnostic:billing_snapshot
Models: model:catalog_loaded, model:fallback_attempt, model:fallback_exhausted, model:auth_cooldown
Providers: provider:degraded, provider:recovered
Agents: agent:hot_added, agent:hot_removed
Channels: channel:registered, channel:deregistered
System: system:error
SSE Chat Streaming
The/api/chat/stream endpoint accepts { "message": string, "agentId"?: string, "locale"?: string }
as its JSON request body (locale is a canonical BCP-47 tag, rejected with 400 when invalid —
same semantics as POST /api/chat). It sends incremental token deltas as token events, followed
by a final done event with the complete response. The same configured HTTP body-size ceiling used by other chat
POST endpoints is enforced before JSON parsing.
Experimental OpenAI-shaped endpoints
These routes implement selected request and response shapes associated with OpenAI endpoints. They are experimental and are not a general OpenAI client, SDK, or drop-in compatibility guarantee. Validate the exact fields and behavior your integration needs against the endpoint reference.For the implemented subset, see Experimental OpenAI-shaped API.
Media Routes
Media routes serve stored media files (images, audio, video, documents). Authentication is optional and depends on gateway configuration; when a token store is configured, requests require at least therpc scope (a narrowly-scoped mcp-client token is rejected with 403).
Media IDs are validated against a safe character pattern (letters, digits, dots, hyphens, underscores) to prevent path traversal. Content types are resolved from sidecar
.meta files or file extension fallback.
Static Files
When the web dashboard is enabled and awebDistPath is configured, the gateway serves the single-page application.
Related
JSON-RPC Methods
All JSON-RPC methods available over WebSocket and HTTP
WebSocket Protocol
WebSocket connection protocol, heartbeat, and error handling
Experimental OpenAI-Shaped API
Implemented request and response shapes for the experimental /v1 routes
Rate Limiting
Rate limiting configuration and behavior
