Integrate
Webhooks
Get a signed event when a job, run or benchmark finishes, with an agent_prompt ready to hand to your agent.
Create an endpoint#
curl -s -X POST https://gpu-router.com/v1/webhooks \
-H "Authorization: Bearer $GPU_ROUTER_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: hook-1" \
-d '{"url": "https://agent.example.com/gpu-router", "events": ["job.completed", "job.failed"], "format": "json"}'The answer is 201 with the endpoint and its secret (whsec_...). The secret is shown in this response only, and again to a retry with the same Idempotency-Key. Store it to check signatures.
| Field | Default | Rule |
|---|---|---|
url | https to a public host. Hosts that are or resolve to private, loopback or link-local addresses are refused. Plain http is allowed only to localhost on a local server. | |
events | all six | At least one event type, from the list below. |
format | json | json, slack or discord. |
An account can have 5 endpoints. The CLI equivalent is gpu-router webhooks add URL --event job.completed; the MCP tool is create_webhook.
Events#
| Type | Sent when |
|---|---|
job.completed | A job ends done. |
job.failed | A job ends failed. |
budget.reached | A job stopped because its budget could not cover the next step. Sent with job.failed. |
run.completed | A run, job or benchmark, succeeded and did not fail its verifier. |
run.failed | A run ended any other way: failed, cancelled, lost, or failed its verifier. |
benchmark.completed | Every run of a benchmark has finished. |
webhook.test | Only from POST /v1/webhooks/{id}/test. It cannot be subscribed to. |
An endpoint receives events that happen after it was created. Each event has a stable id: a retry, or the same event to a second endpoint, carries the same id, so use it to drop duplicates.
Payload#
A json endpoint receives the event as the request body. This is a real job.completed event of the LoRA sample (trimmed):
{
"id": "evt_87131c25caa15e6f9df86976b0ecbbbf",
"type": "job.completed",
"created_at": "2026-10-14T04:10:44.988011Z",
"job_id": "c0c2e4aa09cf4b45a329c4f724df34a8",
"run_id": "29441b0672bd4882a12b581d3fc09081",
"route_id": "658c6f30bb0b4b069622fb193f791536",
"benchmark_id": null,
"stats": {
"gpu": "T4",
"machine": "T4 PCIe 16 GB",
"provider": "Modal",
"status": "done",
"verification": "passed",
"runtime_seconds": "127.398312",
"cost_usd": "0.020894",
"usd_per_unit": "0.455423",
"unit": "1k steps",
"compared": [{"gpu": "T4", "machine": "T4 PCIe 16 GB", "usd_per_unit": "0.455423", "unit": "1k steps"}],
"savings": {"baseline_gpu": "T4", "baseline_cost_usd": "0.020376", "job_cost_usd": "0.116723", "saved_usd": "-0.096347", "percent": "-472.8"},
"spend_usd": "0.116723",
"budget_usd": "1",
"fallbacks": [],
"outputs": [{"path": "metrics.json", "download_url": "https://gpu-router.com/v1/runs/29441b0672bd4882a12b581d3fc09081/outputs/metrics.json"}],
"simulated": true
},
"agent_prompt": "Your LoRA fine-tune job finished on T4 in 127 s for $0.020894 (verified). ..."
}| Field | Meaning |
|---|---|
id | Stable event id, also sent as the GPU-Router-Event-Id header. |
job_id, run_id, route_id, benchmark_id | The subjects of the event; null when they do not apply. |
stats.status | Run status for run events, job state for job events, completed or no_qualified_gpu for benchmarks. |
stats.verification | The run's verification status. |
stats.compared | Verified cost per unit of every GPU tested, cheapest first. |
stats.spend_usd, stats.budget_usd | Job events only. |
stats.fallbacks | Job events only: each GPU whose full-run launch failed to start, with run_id and reason, before the job fell back to the next verified GPU. stats.gpu is the GPU that actually ran. See Routing. |
stats.outputs | Output files with download URLs. Fetch them with your API key as a bearer token. |
stats.simulated | True for a simulated sample run: nothing was launched or billed. |
agent_prompt | What happened and what to do next, written for an AI agent. |
Agents that cannot receive webhooks get the same payload from GET /v1/jobs/{id}/event or the MCP tool wait_for_job.
Verify the signature#
Every request, in every format, carries these headers:
| Header | Value |
|---|---|
GPU-Router-Signature | t=<unix seconds>,v1=<hex> |
GPU-Router-Event | The event type. |
GPU-Router-Event-Id | The event id. |
User-Agent | gpu-router-webhooks |
v1 is HMAC-SHA256 with your secret over <t>. followed by the raw body bytes. Recompute it over the exact bytes you received, compare in constant time, and reject old timestamps. t is set on each attempt, so retries carry a fresh one.
import hashlib, hmac, time
def verified(header: str, body: bytes, secret: str) -> bool:
parts = dict(item.split("=", 1) for item in header.split(","))
expected = hmac.new(secret.encode(), f"{parts['t']}.".encode() + body, hashlib.sha256).hexdigest()
return hmac.compare_digest(expected, parts["v1"]) and abs(time.time() - int(parts["t"])) < 300Verify before parsing the JSON: re-serialising the body changes the bytes and breaks the signature.
Test the endpoint#
curl -s -X POST https://gpu-router.com/v1/webhooks/$HOOK_ID/test \
-H "Authorization: Bearer $GPU_ROUTER_API_KEY" -H "Idempotency-Key: test-1"
curl -s https://gpu-router.com/v1/webhooks/$HOOK_ID/deliveries -H "Authorization: Bearer $GPU_ROUTER_API_KEY"The test answers 202 with the queued delivery and sends a signed webhook.test event right after. Its agent_prompt says no action is needed. Poll the delivery log for its status.
Retries and 410 Gone#
A 2xx answer marks the delivery delivered. Anything else is retried with a doubling delay, starting at 30 seconds, for up to 24 hours after the event was queued.
| Your answer | What GPU Router does |
|---|---|
2xx | Delivered. |
408, 429, 5xx, timeout (10 s) or connection error | Retried until the 24 hour window ends, then failed. |
Other 4xx | failed at once, no retry. |
410 Gone | failed, and the endpoint is disabled with a disabled_reason. Fix the URL if needed and send PATCH /v1/webhooks/{id} with {"enabled": true}. |
Deliveries for one route are sent in order: a delivery waits while an earlier one for the same route is waiting to be retried. Retry a failed delivery by hand with POST /v1/webhooks/{id}/deliveries/{delivery_id}/retry; retrying a pending or delivered one answers 409 WEBHOOK_DELIVERY_NOT_FAILED.
On a server with background tasks, new events are collected on every run poll (every 15 seconds by default) and due deliveries are sent every second. On a serverless deployment, events are collected and sent when you call a jobs, runs or benchmark endpoint, and by the daily sweep. A demo account's deliveries are simulated and never sent.
Formats#
| Format | Body |
|---|---|
json | The event above. |
slack | {"text": ...} for a Slack incoming webhook URL. |
discord | {"content": ..., "allowed_mentions": {"parse": []}}, cut to 2000 characters. |
The chat text is the event name, the agent_prompt, a stats line (GPU, runtime, cost, verification, spend of budget) and a link to the job, run or route page.
Manage endpoints#
| Call | Does |
|---|---|
GET /v1/webhooks | Your endpoints, oldest first, without secrets. |
PATCH /v1/webhooks/{id} | Change url, events, format or enabled. Enabling clears disabled_reason. |
DELETE /v1/webhooks/{id} | Delete the endpoint and its delivery log; pending deliveries are dropped. |
GET /v1/webhooks/{id}/deliveries | The delivery log, newest first: status, attempts, last status code and error, next attempt. |
Next steps#
- Idempotency: why creating an endpoint needs a key.
- POST /v1/webhooks reference