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.

FieldDefaultRule
urlhttps 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.
eventsall sixAt least one event type, from the list below.
formatjsonjson, 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#

TypeSent when
job.completedA job ends done.
job.failedA job ends failed.
budget.reachedA job stopped because its budget could not cover the next step. Sent with job.failed.
run.completedA run, job or benchmark, succeeded and did not fail its verifier.
run.failedA run ended any other way: failed, cancelled, lost, or failed its verifier.
benchmark.completedEvery run of a benchmark has finished.
webhook.testOnly 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). ..."
}
FieldMeaning
idStable event id, also sent as the GPU-Router-Event-Id header.
job_id, run_id, route_id, benchmark_idThe subjects of the event; null when they do not apply.
stats.statusRun status for run events, job state for job events, completed or no_qualified_gpu for benchmarks.
stats.verificationThe run's verification status.
stats.comparedVerified cost per unit of every GPU tested, cheapest first.
stats.spend_usd, stats.budget_usdJob events only.
stats.fallbacksJob 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.outputsOutput files with download URLs. Fetch them with your API key as a bearer token.
stats.simulatedTrue for a simulated sample run: nothing was launched or billed.
agent_promptWhat 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:

HeaderValue
GPU-Router-Signaturet=<unix seconds>,v1=<hex>
GPU-Router-EventThe event type.
GPU-Router-Event-IdThe event id.
User-Agentgpu-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"])) < 300

Verify 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 answerWhat GPU Router does
2xxDelivered.
408, 429, 5xx, timeout (10 s) or connection errorRetried until the 24 hour window ends, then failed.
Other 4xxfailed at once, no retry.
410 Gonefailed, 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#

FormatBody
jsonThe 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#

CallDoes
GET /v1/webhooksYour 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}/deliveriesThe delivery log, newest first: status, attempts, last status code and error, next attempt.

Next steps#