Synchronous calls have about two minutes
A normal (synchronous) call has about 115 s to return. Long-running endpoints such as the AI asks fit their retries into that window: if they can’t finish, you get an error response instead of a dropped connection. Failed calls are not billed.- Set your HTTP client timeout to 130 s for AI endpoints. A shorter timeout aborts answers that would have arrived.
- If your connection drops before the response arrives, the call is not billed.
Run slow calls asynchronously
AddPrefer: respond-async, wait=25 to any read request. Async calls are not bound by that window.
-
If the call finishes within
waitseconds (1–120), you get the normal response. -
Otherwise you get
202 Acceptedwith arequest_id:
GET /v1/requests/{request_id}. Polling is free. It returns 202 while the call runs, then the original status, headers and body. The finished result is held in memory only, never written to disk, for at most 15 minutes so you can collect it. After that, polling returns 404 request_not_found.
The call is billed once, when it completes. A call that never completes is not billed. Don’t re-send the original request while it runs: that starts, and bills, a second call.
Get the result by webhook
AddX-Callback-URL: https://your-server.example/hook to an async call (it needs Prefer: respond-async). When the call completes, ScrapeBadger POSTs the result there as JSON. A call that finishes within wait still gets its webhook, as well as the normal response.
statusandbodyare the call’s own, errors included. A body over 1 MB is left out ("body": null, "body_omitted": true): fetch it fromresult_urlwithin 15 minutes.- The URL must be
httpson a public address. Private, loopback and cloud-metadata addresses are refused, and redirects are not followed. A bad URL gets400 invalid_callback_urlbefore the call runs, and nothing is billed. - Answer with any
2xx. On a timeout, a connection error,408,429or5xx, the delivery is retried after 10 s, 60 s and 5 min (4 attempts in total). Other statuses are final. Deliveries can repeat, so deduplicate onrequest_id. GET /v1/requests/{request_id}reports the delivery: as acallbackobject (status:pending/delivered/failed,attempts,last_error) while the call runs, and asX-Callback-StatusandX-Callback-Attemptsheaders on the final response.- Calls refused before they run (invalid key, no credits, rate limit) answer synchronously and send no webhook.
- Deliveries in progress don’t survive a restart of our gateway. If a restart interrupts retries, the poll reports the delivery as
failedwithlast_error: "interrupted (gateway restart)". Fetch the result fromresult_urlwhile it is still kept.
Verify the signature
Every delivery is signed with your account’s webhook secret. Get the secret fromGET /v1/account/webhook-secret, and rotate it with POST /v1/account/webhook-secret/rotate. Both need a full-access API key: a key restricted to some APIs gets 403 full_access_required. X-ScrapeBadger-Signature is sha256= followed by the hex HMAC-SHA256 of the raw request body. Check it before you parse the body, and reject stale sent_at values to stop replays. This is the same scheme stream monitors use.
Submit a batch
POST /v1/batch takes up to 100 GET reads and returns a request_id for each, at once:
- Each item is an ordinary async request under your key. It has the same authentication, permissions, credit check, rate limit and price as if you had sent it alone. Submitting the batch is free.
- Items are checked against your balance before any of them start, at each endpoint’s base price (what
POST /v1/quotereports). Items whose price no longer fits, after the items before them and your other batch items still running, come back as402 insufficient_creditsand are not started. - An item that can’t start (for example
402as above,429over your rate limit, or404unknown endpoint) comes back with"accepted": false, itsstatusanderror. It is not billed, and you can resubmit just that item later. - Poll each
poll_url, or passcallback_urlto get one webhook per item, each withbatch_idset. - At most 10 items of one batch run at a time. The others wait their turn and show as
runningwhen polled. - A batch over 100 items gets
413 batch_too_large. - Items still waiting for a slot when our gateway restarts are dropped. They are not billed, and polling them returns
404 request_not_foundwithin about 5 minutes. Resubmit those. - Unclaimed trial keys can’t batch (
403 trial_not_allowed) or use webhooks. They can still usePrefer: respond-async, one call at a time: a second call while the first is still running gets429 trial_concurrency.
Concurrency
There is no per-key concurrency limit beyond your plan’s rate limit. AI asks render a live answer, so latency rises when many run at once. Start around 10 in parallel per engine and scale up while you watch the error rate. A502 on an AI ask means the engine produced no usable answer on that attempt. It is not billed, and retrying it is safe.
