Hadrian is experimental alpha software. Do not use in production.
Hadrian
ConfigurationFeatures

WebSocket

Configure real-time event subscriptions via WebSocket

The [features.websocket] section configures real-time event subscriptions. Clients can connect to /ws/events to receive server events like audit logs, usage updates, and budget alerts.

Configuration Reference

[features.websocket]
enabled = true
require_auth = true
ping_interval_secs = 30
pong_timeout_secs = 60
max_connections = 1000
channel_capacity = 1024
KeyTypeDefaultDescription
enabledbooleantrueEnable WebSocket endpoint
require_authbooleanfalseRequire authentication
ping_interval_secsinteger30Keepalive ping interval
pong_timeout_secsinteger60Pong response timeout
max_connectionsinteger1000Maximum concurrent connections
channel_capacityinteger1024Event buffer size

Authentication

WebSocket connections can be authenticated via:

Query Parameter Token

ws://gateway:8080/ws/events?token=gw_live_abc123...

Browser connections with an active OIDC session are authenticated automatically.

Set require_auth = true in production to prevent unauthorized access to real-time events.

Event Types

Clients can subscribe to:

  • Audit logs - Request/response events, guardrails violations
  • Usage updates - Token counts, cost tracking
  • Budget alerts - Threshold warnings, budget exceeded
  • Circuit breaker - Provider health state changes
  • System events - Configuration changes, startup/shutdown

Complete Examples

Development

[features.websocket]
enabled = true
require_auth = false
ping_interval_secs = 30
pong_timeout_secs = 60
max_connections = 100
channel_capacity = 256

Production

[features.websocket]
enabled = true
require_auth = true
ping_interval_secs = 30
pong_timeout_secs = 60
max_connections = 5000
channel_capacity = 4096

Disabled

[features.websocket]
enabled = false

Connection Handling

Keepalive

The server sends ping frames at ping_interval_secs. If no pong is received within pong_timeout_secs, the connection is terminated.

Backpressure

When the event buffer (channel_capacity) fills up, slow subscribers start missing events (lagging). Increase channel_capacity for high-volume deployments.

Connection Limits

When max_connections is reached, new connections are rejected. Set to 0 for unlimited (not recommended).

Client Example

const ws = new WebSocket("ws://gateway:8080/ws/events?token=gw_live_...");

ws.onmessage = (event) => {
  const data = JSON.parse(event.data);
  console.log("Event:", data.type, data.payload);
};

ws.onclose = () => {
  console.log("Connection closed, reconnecting...");
  // Implement reconnection logic
};

See Also

On this page