Webhooks
Deliver project lifecycle events to HTTPS endpoints.
Webhooks deliver project lifecycle events to your HTTPS endpoint. Use them to update an inventory or start a workflow when a client or tunnel comes online or goes away. Pro and Enterprise projects can configure destinations in the Dashboard or through the Control plane API.
Send a first delivery
- Open the project’s Webhooks in the Dashboard and select Create new webhook.
- Add the receiver’s HTTPS URL, select a lifecycle event such as
tunnel.created, and select Create webhook. - Save the signing secret shown after creation and configure the receiver to verify requests before acknowledging them.
- Create a tunnel in the same project. Open the destination’s delivery history and check that the receiver returned a
2xxresponse.
Event catalog
Webhook destinations can subscribe to these lifecycle events:
| Event | Description |
|---|---|
client.created | A tunnel client connected and authenticated against the project. |
client.deleted | A tunnel client disconnected or was removed from the active project state. |
tunnel.created | A tunnel was created and became available for the project. |
tunnel.deleted | A tunnel was deleted or stopped publishing for the project. |
webtty.session.created | A WebTTY session was created. |
webtty.session.updated | WebTTY session or session-group metadata changed. |
webtty.session.ended | A WebTTY session ended. |
webtty.participant.joined | A participant joined a WebTTY session. |
webtty.participant.updated | A WebTTY participant's state changed. |
webtty.participant.left | A participant left a WebTTY session. |
webtty.control.requested | A participant requested control of a WebTTY session. |
webtty.control.granted | A WebTTY control request was granted. |
webtty.control.refused | A WebTTY control request was refused. |
webtty.control.revoked | A WebTTY control grant was revoked. |
Traffic logs, connection logs, and stream.summary records are not emitted through webhooks.
Payload
Each request body is the canonical event JSON:
{
"id": "event_id",
"type": "tunnel.created",
"created_at": "2026-06-01T12:00:00Z",
"workspace_id": "workspace_id",
"project_id": "project_id",
"cluster_id": "cluster_id",
"user_id": "user_id",
"object": {
"id": "tunnel_id",
"client_id": "client_id",
"status": "online",
"labels": { "device_id": "device-42" }
}
}The body’s id is the event idempotency key. The rstream-delivery-id
header identifies delivery of that event to one destination. Its value stays
the same when that delivery is retried. Use delivery history to inspect
individual attempts.
user_id is optional. An operation performed by a workspace Token has no human user actor; do not substitute the Token creator's ID. Use the event's workspace and project fields to identify its resource context.
Delivery behavior
rstream stores lifecycle events and delivery records before sending HTTPS requests. Failed deliveries are retried with exponential backoff.
Delivery is at least once. Receivers use the event id as an idempotency key because recovery and retries can produce more than one delivery attempt for the same event.
Webhook endpoints must return a 2xx status code for success. Other status codes, network errors, and request timeouts are recorded as failed attempts. Response bodies are retained only up to the configured cap.
Delivery history follows the project event retention window. Delivery attempts are attached to their delivery record and are removed when the delivery expires.
Signatures
Verify deliveries with the signing secret returned when you create or rotate the destination. Keep that secret in the receiving backend's secret store.
Each webhook request includes:
| Header | Purpose |
|---|---|
rstream-signature | HMAC signature for the raw request body. |
rstream-event-id | Canonical lifecycle event id. |
rstream-event-type | Lifecycle event type. |
rstream-webhook-id | Webhook endpoint that received the delivery. |
rstream-delivery-id | Delivery record id for this webhook endpoint. |
The signing secret is returned when you create or rotate a destination. Store it securely; list and detail responses do not return it. Rotation retains the preceding secret for 24 hours so receivers can switch without interrupting delivery.
The signature header uses this shape:
t=<unix_timestamp>,v1=<hex_hmac>The HMAC is SHA-256 over:
<unix_timestamp>.<raw_request_body>Verify against the raw body bytes before parsing JSON. The JavaScript, Python, and Java SDKs perform signature verification and event parsing in the same call, so the receiving route can keep the trust boundary small.
Receiver compatibility
Choose the destination's event filters to match the receiver's parser:
| Receiver helper | Supported event types |
|---|---|
JavaScript RstreamWebhookResource.event() | All client, tunnel and WebTTY events in the catalog above. |
Python verify_event() | client.created, client.deleted, tunnel.created, tunnel.deleted. |
Java Webhooks.event() | client.created, client.deleted, tunnel.created, tunnel.deleted. |
Python and Java reject WebTTY payloads even when their signatures are valid. Select only their four supported event types for those receivers. The examples below use that client/tunnel subset. The Go CLI's local forwarding mode has its own catalog limitation.
With Python and FastAPI:
import os
from fastapi import Header, HTTPException, Request
import rstream
async def parse_rstream_webhook(
request: Request,
rstream_signature: str = Header(alias="rstream-signature"),
) -> rstream.WebhookEvent:
secret = os.environ.get("RSTREAM_WEBHOOK_SECRET")
if secret is None:
raise HTTPException(status_code=500, detail="Missing webhook secret.")
payload = await request.body()
try:
return rstream.verify_event(payload, rstream_signature, secret)
except rstream.RstreamError as error:
raise HTTPException(status_code=400, detail=str(error)) from errorWith JavaScript:
import { Buffer } from "node:buffer";
import { RstreamWebhookResource } from "@rstreamlabs/tunnels";
import type { WebhookEvent } from "@rstreamlabs/tunnels";
const webhooks = new RstreamWebhookResource();
type ParsedWebhookEvent = WebhookEvent & { id: string; created_at: string };
function requireCanonicalFields(event: WebhookEvent): ParsedWebhookEvent {
if (!event.id || !event.created_at) {
throw new Error("Webhook event is missing canonical metadata.");
}
return { ...event, id: event.id, created_at: event.created_at };
}
export async function parseRstreamWebhook(
request: Request,
): Promise<ParsedWebhookEvent> {
const secret = process.env.RSTREAM_WEBHOOK_SECRET;
const signature = request.headers.get("rstream-signature");
if (!secret || !signature) {
throw new Error("Missing webhook secret or signature.");
}
const rawBody = Buffer.from(await request.arrayBuffer());
const event = await webhooks.event(rawBody, signature, secret);
return requireCanonicalFields(event);
}After parsing, route the event by type. Labels are often the stable bridge
between runtime resources and application records: for example a device id,
customer id, environment, or service role. This mapper handles client and tunnel
presence changes and returns null for other event types.
import type { WebhookEvent } from "@rstreamlabs/tunnels";
type ParsedWebhookEvent = WebhookEvent & { id: string; created_at: string };
type LifecycleChange = {
eventId: string;
labels: Record<string, string>;
observedAt: string;
resourceId: string;
state: "online" | "offline";
};
function lifecycleChange(event: ParsedWebhookEvent): LifecycleChange | null {
switch (event.type) {
case "client.created":
case "tunnel.created":
return {
eventId: event.id,
labels: event.object.labels ?? {},
observedAt: event.created_at,
resourceId: event.object.id,
state: "online",
};
case "client.deleted":
case "tunnel.deleted":
return {
eventId: event.id,
labels: event.object.labels ?? {},
observedAt: event.created_at,
resourceId: event.object.id,
state: "offline",
};
default:
return null;
}
}During secret rotation, rstream may send more than one v1 signature in the same header. A request is valid when any signature matches an active secret.
Local receiver tests
rstream events --webhook is the local receiver development path for live
project events. The CLI keeps the watch stream local, but sends the receiver the
same signed request format as a configured webhook delivery. The CLI
builds its payload from live watch events and may generate the event and
delivery identifiers locally. Direct CE events can omit hosted project,
workspace and cluster metadata.
rstream events \
--transport sse \
--webhook \
--webhook-secret "$RSTREAM_WEBHOOK_SECRET" \
--events tunnel.created,tunnel.deleted \
--forward-to http://localhost:3000/api/rstream/webhookSet RSTREAM_WEBHOOK_SECRET to the receiver's test secret. Create and stop a
project tunnel to verify both requests with the receiver. If no --webhook-secret is provided, the CLI prints a generated
whsec_... secret to stderr for that receiver session. Add
--include-webhook-headers when inspecting stdout instead of forwarding to an
HTTP endpoint.
Use this mode to exercise a receiver against the live events from a direct or hosted Engine connection. It runs for the lifetime of the CLI process. Configure a project webhook when you need queued retries and persistent delivery history.
The local watcher can sign client.created, client.deleted,
tunnel.created and tunnel.deleted. Stop it with Ctrl+C after verifying
the receiver.
Use the receiver compatibility table to choose a parser. The Go and CLI guide covers the local watcher and Go delivery methods.
Destinations
Open a Pro project or Enterprise workspace project in the Dashboard as a workspace owner or admin. In the project's Webhooks section, create a webhook, enter the receiver's HTTPS URL and select the event types it handles. Choose Create webhook and save the signing secret in the receiver's secret store.
Configured destinations require a public HTTPS endpoint without embedded credentials. For a receiver on loopback or a private development network, use Local receiver tests.
Trigger a subscribed event, such as creating a tunnel if you subscribed to
tunnel.created. Open the destination's delivery list and check the recorded
attempt for a 2xx response. Select the delivery to inspect individual
attempts and diagnose errors. The API exposes the same records.
Disable or delete a test destination when it is no longer needed.
API and MCP
Project events APIs inspect canonical lifecycle events. Webhook delivery APIs inspect per-webhook delivery state, attempts, response codes, response bodies, and response times.
Use network.webhooks.read-only to inspect webhook destinations, deliveries, and metrics. network.webhooks.read-write also allows creation, updates, deletion, and signing-secret rotation; managing a destination still requires an owner or admin role in its workspace. Use a personal Token or an approved App with these permissions. The approved project boundary and your current workspace access apply to each request.
MCP keeps the same boundary between the event stream and delivery diagnostics:
rstream_project_events_listlists canonical lifecycle events.rstream_project_logslists traffic and connection logs.rstream_project_webhook_deliveries_listandrstream_project_webhook_delivery_getinspect webhook delivery context.