Async Jobs
How a slow route runs as a job: part of the API guide. Payment is the same on every page: Paying with x402 or Paying with MPP.
Async jobs (slow routes)
Reports, video, the premium image and /api/decide/execute can take one to four minutes. Each slow route says so in machine-readable form: an async block on its /api/pricing row and its /openapi.json operation (x-agent402-async) with expectedSeconds (the typical measured run) and maxSeconds (the run budget), a "slow" marker on its /llms.txt line, and on its 402 an X-Async-Recommended: respond-async; expected-seconds=…; max-seconds=… header plus the same async block in the JSON body (the PAYMENT-REQUIRED header is unchanged). Send the paid call with Prefer: respond-async and it answers 202 at once with a job link instead of holding the connection. The route-execute tiers, seller-payability and the fast and pro image tiers accept the header too, without being advertised as slow:
curl -X POST https://agent402.tools/v1/research \
-H 'Content-Type: application/json' \
-H 'Prefer: respond-async' \
-H 'PAYMENT-SIGNATURE: <your payment>' \
-d '{"query":"x402 adoption"}'
# 202 {"jobId":"…","status":"working","state":"queued","stage":"queued","statusUrl":"/api/jobs/…","pollIntervalSeconds":5}
curl https://agent402.tools/api/jobs/<jobId> # free; poll until status is completed or failed, waiting Retry-After seconds
# {"status":"working","state":"running","stage":"searching","steps":{"done":1,"total":5},"progress":0.2,"progressEstimated":false,"etaSeconds":64,…}
status keeps its original values (working, then completed or failed), so an existing poller is unchanged. The lifecycle is in state: queued until the paid handler starts (the payment has been verified), running while it works, then succeeded or failed. While it runs it reports a stage (video: submitted, generating, downloading, encoding; reports: their named steps with steps.done of steps.total), a progress from 0 to 1 and an etaSeconds. A route that does not report its own steps shows elapsed time against its typical run, marked progressEstimated: true. Every state that is not final sets Retry-After; wait that long between polls. agent402-client and agent402-mcp do all of this on their own for the slow routes.
The call runs on the server with your payment and settles only when the answer is ready, except a Tempo transfer sent before the call, which is repaid after on-chain proof if the run fails: a failed run is not charged on x402, and a refused payment ends the job with its 402. A completed job carries the route's answer in result.body and its payment receipt in result.headers. The link is the job's only key and expires after one hour; a client may run four jobs at once. A call without a payment gets the ordinary 402. A paid call to a slow route whose maxSeconds is past the sync window (20 s) needs one of two headers: Prefer: respond-async (a job, as above) or Prefer: wait=<maxSeconds> (the answer on this connection; the async block names it as preferWait). A paid call with neither is answered 400 with error: "respond_async_required" before any payment is verified, so nothing is charged; agent402-client 0.8.16 and later is run as a job on its own. The routes that accept the header without being advertised as slow behave as before. Some calls are paid before they run; a failed one can be retried free with the same payment, or is refunded.
Job-done notices
On a server that sets JOB_NOTIFY=on (off by default), a job can tell you when it ends, so you do not have to poll. Both options are optional and can be used together. Either notice is sent only for a run whose payment or proof of work the gate accepted: a job whose payment is refused ends with its 402 and no notice.
- Webhook: send
X-Agent402-Notify-Url: https://…besidePrefer: respond-async. The URL must be https, carry no credentials and name a host that resolves to public addresses only; anything else is refused with400before the job is made, so nothing runs or is charged. The202carriesnotify.secret. When the job reaches a final state, the server sends onePOSTwith{"event":"job.finished","kind":"job","id":"…","status":"completed","statusUrl":"/api/jobs/…","finishedAt":"…"}and anX-Agent402-Signature: t=<unix seconds>,v1=<hex HMAC-SHA256 of "<t>.<body>" with the secret>header (the same scheme as price webhooks). The result itself is never sent; fetch it fromstatusUrl. A redirect is not followed. An answer other than2xxor410is retried a few times, then dropped. - Email: on a job paid with a prepaid credits key (
Authorization: Bearer a402_…), send"notifyEmail": truein the JSON body (orX-Agent402-Notify-Email: account). The one message goes to the email on that credits balance, the address its card purchase gave, where its receipts already go. Naming that same address also works; any other address, or an email asked for on a call paid any other way, is refused with400before the job is made, so nothing runs or is charged, and the refusal names no address. The field is taken out before the tool reads its input, and the address is never shown in an answer, a log or the job link. When the job ends, one plain message names the job, its final status and, when it completed, the link to its result. The message says why it was sent, is the only one sent for that job, and carries a link to a page whose button stops all job-done email to that address (opening the link alone changes nothing; the stop also rides as a one-clickList-Unsubscribeheader); the stop list holds a keyed hash of the address, never the address. Sends are limited per address and per client address (an IPv6 client by its /64). Past a limit the call still runs as usual and the202saysnotify.email: "not-sent". Whatever is chosen, the202's job link (GET /api/jobs/<id>) is the status page an app can poll.
The URL and the address are kept in the server's memory only, never in the job record, and are deleted once the notice is sent or given up, when the job is canceled, or when the job link expires, whichever comes first. A notice that cannot be delivered leaves the job's result and its charge as they were. On the MCP connector a call that runs as a task takes the webhook in _meta["org.agent402/notify-url"]; a task is paid from a wallet, so an email (notifyEmail or _meta["org.agent402/notify-email"]) is refused there before the run (see MCP Connector).