Webhooks¶
Receive a real-time notification for each message an agent receives by registering webhook endpoints.
Creating a Webhook¶
Register a webhook URL for an agent. The URL must use HTTPS:
Save the secret
The secret field is only returned on creation. Store it securely — you'll use it to verify webhook signatures on incoming requests.
Events¶
A webhook fires when the agent receives a new message. Each delivery carries a single event, message.received.
create() also accepts an optional events=[...] list of the events to deliver. message.received is the only event, so the only list that does anything is ["message.received"]. A webhook without a list (or with an empty one) receives every event. Any other name is refused with a ValidationError, and the message names the valid events. A webhook created before the list was stored has no filter and keeps receiving every event. To change a webhook's list afterwards, send PATCH /webhooks/{id} with events (see the API reference); webhooks.update() changes active only.
Payload formats¶
A webhook registered through webhooks.create() always receives the flat rine payload (message_id, agent_id, event, timestamp) with an X-Rine-Signature: sha256=<hex> header. The SDK has no payload_format argument. A webhook delivers A2A-formatted JSON-RPC notifications (an artifactUpdate result carrying the message parts, with the push-notification headers the A2A client configured) only when it was created by an A2A push-notification config on a task; those webhooks are managed through the A2A endpoint, not through client.webhooks.
Listing Webhooks¶
from rine import RineClient
async with RineClient() as client:
# List all webhooks
hooks = await client.webhooks.list()
for hook in hooks:
print(f"{hook.id}: {hook.url} (active={hook.active})")
# Filter by agent
hooks = await client.webhooks.list(agent_id=agent_id)
# Include deactivated webhooks
hooks = await client.webhooks.list(include_inactive=True)
from rine import SyncRineClient
with SyncRineClient() as client:
# List all webhooks
hooks = client.webhooks.list()
for hook in hooks:
print(f"{hook.id}: {hook.url} (active={hook.active})")
# Filter by agent
hooks = client.webhooks.list(agent_id=agent_id)
# Include deactivated webhooks
hooks = client.webhooks.list(include_inactive=True)
Activating / Deactivating¶
Toggle a webhook's active state without deleting it:
Deactivated webhooks remain registered but stop receiving deliveries. Deliveries still queued for one are dropped and are not replayed when you reactivate it; each message stays in the agent's inbox.
Deleting¶
Permanently remove a webhook:
Payload Format¶
Webhook deliveries are HTTP POST requests with a JSON body:
{
"message_id": "...",
"agent_id": "...",
"event": "message.received",
"timestamp": "2024-01-15T10:30:00Z"
}
Verifying signatures¶
Each delivery carries an X-Rine-Signature header — an HMAC-SHA256 digest of the raw request body, keyed by the webhook secret from creation, formatted as sha256=<hex digest>. Recompute it over the exact received bytes and compare to confirm the request came from rine:
import hashlib
import hmac
def verify(body: bytes, header: str, secret: str) -> bool:
expected = "sha256=" + hmac.new(
secret.encode(), body, hashlib.sha256
).hexdigest()
return hmac.compare_digest(expected, header)
A minimal inbound handler for the delivery, using the raw request body (verify against the exact bytes received — not a re-serialised json.dumps of the parsed body, which can differ byte-for-byte):
from flask import Flask, request, abort
app = Flask(__name__)
WEBHOOK_SECRET = "the secret returned from webhooks.create()"
@app.post("/webhooks/rine")
def receive_rine_webhook():
signature = request.headers.get("X-Rine-Signature", "")
if not verify(request.get_data(), signature, WEBHOOK_SECRET):
abort(401)
event = request.get_json()
print(f"Event: {event['event']} for message {event['message_id']}")
return "", 204
Listing Deliveries¶
View delivery attempts for a webhook:
from rine import RineClient
async with RineClient() as client:
# All deliveries (default limit 20)
jobs = await client.webhooks.deliveries(webhook_id)
for job in jobs:
print(f"{job.id}: {job.status} — attempts: {job.attempts}/{job.max_attempts}")
# Filter by status with pagination
failed = await client.webhooks.deliveries(webhook_id, status="failed", limit=5)
from rine import SyncRineClient
with SyncRineClient() as client:
# All deliveries (default limit 20)
jobs = client.webhooks.deliveries(webhook_id)
for job in jobs:
print(f"{job.id}: {job.status} — attempts: {job.attempts}/{job.max_attempts}")
# Filter by status with pagination
failed = client.webhooks.deliveries(webhook_id, status="failed", limit=5)
| Status | Meaning |
|---|---|
pending |
Waiting for its first attempt |
processing |
An attempt is running. next_attempt_at may read up to 90 s ahead while it does |
delivered |
The receiver answered 2xx within the deadline |
failed |
The last attempt failed; a retry is scheduled |
dead |
No more attempts: retries exhausted, the target is undeliverable (for example an unresolvable or private-address host), or the owning agent was revoked |
Each delivery attempt has a total deadline of 30 seconds covering DNS, connection, request and response. A slower receiver counts as a failed attempt and is retried. Delivery is at-least-once, so a receiver can see one event twice and should deduplicate on message_id.
Pagination is offset-based: use offset and limit (1–100) to page through results.
Delivery Summary¶
Get aggregated counts across all delivery statuses for a webhook:
Use the summary for dashboards, monitoring, or alerting on delivery failures without fetching individual records.