[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"help:\u002Fhelp\u002Fapi-webhooks-idempotency-and-rate-limits":3},{"id":4,"title":5,"body":6,"category":286,"description":287,"extension":288,"meta":289,"navigation":290,"order":291,"path":292,"seo":293,"stem":294,"__hash__":295},"help\u002Fhelp\u002Fapi-webhooks-idempotency-and-rate-limits.md","API webhooks, safe retries and rate limits",{"type":7,"value":8,"toc":275},"minimark",[9,14,35,40,64,70,74,84,87,91,94,118,121,131,138,142,153,183,187,190,234,237,257],[10,11,13],"h2",{"id":12},"webhooks","Webhooks",[15,16,17,18,22,23,26,27,30,31,34],"p",{},"Pass a ",[19,20,21],"code",{},"webhook_url"," when you submit a task and we send one signed POST to that address when the task ends as ",[19,24,25],{},"completed",", ",[19,28,29],{},"failed"," or ",[19,32,33],{},"cancelled",". You can still poll the task as well.",[36,37,39],"h3",{"id":38},"set-the-signing-secret-first","Set the signing secret first",[15,41,42,43,47,48,51,52,55,56,59,60,63],{},"Your organisation has one signing secret. An admin makes it in ",[44,45,46],"strong",{},"Settings › Developers",", in the ",[44,49,50],{},"Webhook signing secret"," section, with ",[44,53,54],{},"Create",". ",[44,57,58],{},"Rotate"," replaces it and ",[44,61,62],{},"Clear"," removes it. The secret is shown once when you create or rotate it, so save it then.",[15,65,66,67,69],{},"Until a secret exists, a submit with a ",[19,68,21],{}," is refused with a 400. If you clear it later, deliveries not yet sent are dropped, because they cannot be signed.",[36,71,73],{"id":72},"your-endpoint","Your endpoint",[75,76,77,81],"ul",{},[78,79,80],"li",{},"It must be reachable from the public internet.",[78,82,83],{},"It must listen on port 80, 443, 8080 or 8443.",[15,85,86],{},"If a delivery fails we try again: immediately, then after 5 minutes, 15 minutes, 1 hour, 4 hours, 12 hours, 24 hours and 48 hours. That is 8 attempts, and then we give up.",[36,88,90],{"id":89},"check-the-signature","Check the signature",[15,92,93],{},"Each delivery carries three headers.",[75,95,96,106,112],{},[78,97,98,101,102,105],{},[19,99,100],{},"X-DataAtScale-Signature",": ",[19,103,104],{},"sha256="," followed by a hex HMAC.",[78,107,108,111],{},[19,109,110],{},"X-DataAtScale-Timestamp",": Unix seconds at delivery time.",[78,113,114,117],{},[19,115,116],{},"Content-Type: application\u002Fjson",".",[15,119,120],{},"The signature is the HMAC-SHA256 of the timestamp, a dot, and the raw body, made with your secret. Compare in constant time and reject deliveries older than about 5 minutes.",[122,123,128],"pre",{"className":124,"code":126,"language":127},[125],"language-text","import hmac, hashlib, time\n\ndef verify(secret: str, body: bytes, sig_header: str,\n           ts_header: str, max_age_s: int = 300) -> bool:\n    if not (sig_header and ts_header and ts_header.isdigit()):\n        return False\n    if abs(int(time.time()) - int(ts_header)) > max_age_s:\n        return False\n    expected = \"sha256=\" + hmac.new(\n        secret.encode(),\n        f\"{ts_header}.\".encode() + body,\n        hashlib.sha256,\n    ).hexdigest()\n    return hmac.compare_digest(expected, sig_header)\n","text",[19,129,126],{"__ignoreMap":130},"",[15,132,133,134,137],{},"In the dashboard, the ",[44,135,136],{},"Webhook URL"," box in the \"Name it\" step of Find creators is called when the search finishes. The address there must start with https:\u002F\u002F, and it needs the signing secret too.",[10,139,141],{"id":140},"repeat-a-request-safely","Repeat a request safely",[15,143,144,145,148,149,152],{},"If a POST times out you cannot tell whether it went through. Send an ",[19,146,147],{},"Idempotency-Key"," header with each POST, such as a UUID you make for that request, and use the same key when you send it again. Within 24 hours you get the first response back, marked ",[19,150,151],{},"Idempotent-Replayed: true",", and not a second task or a second charge.",[75,154,155,161,167,170,176],{},[78,156,157,158,117],{},"A key belongs to your organisation and one request. The same key with a different body is refused as ",[19,159,160],{},"idempotency_key_mismatch",[78,162,163,164,117],{},"While the first request is still running, the same key answers 409 ",[19,165,166],{},"idempotency_in_progress",[78,168,169],{},"Only successful answers and invalid-input errors are kept. Other refusals, such as not enough credits or a daily limit, are not kept, so after you fix the cause the same key runs the request.",[78,171,172,173,117],{},"Answers that hold a secret or a link shown once, such as API keys, invites and checkout links, are not kept. The same key then answers 409 ",[19,174,175],{},"idempotency_already_completed",[78,177,178,179,182],{},"Sign-in and account routes under ",[19,180,181],{},"\u002Fv1\u002Fauth\u002F"," ignore the header.",[10,184,186],{"id":185},"rate-limits","Rate limits",[15,188,189],{},"Each route has its own limit over a fixed 10-minute window. Signed-in routes count per organisation, and public routes count per IP address.",[191,192,193,206],"table",{},[194,195,196],"thead",{},[197,198,199,203],"tr",{},[200,201,202],"th",{},"Kind of request",[200,204,205],{},"Limit per 10 minutes",[207,208,209,218,226],"tbody",{},[197,210,211,215],{},[212,213,214],"td",{},"Free checks: estimates, input checks, match counts",[212,216,217],{},"300",[197,219,220,223],{},[212,221,222],{},"Reads, such as GET requests for tasks and results",[212,224,225],{},"20,000",[197,227,228,231],{},[212,229,230],{},"Writes, such as submits and cancels",[212,232,233],{},"2,000",[15,235,236],{},"Each response carries three headers:",[75,238,239,245,251],{},[78,240,241,244],{},[19,242,243],{},"RateLimit-Limit",": the route's limit for the window.",[78,246,247,250],{},[19,248,249],{},"RateLimit-Remaining",": what is left in this window.",[78,252,253,256],{},[19,254,255],{},"RateLimit-Reset",": seconds until the window ends.",[15,258,259,260,262,263,266,267,270,271,274],{},"When you pass the limit you get a 429 with ",[19,261,19],{}," set to ",[19,264,265],{},"rate_limited",", a ",[19,268,269],{},"Retry-After"," header, and ",[19,272,273],{},"resets_in_s"," in the body. Wait that many seconds. This is separate from your daily limits, which reset at midnight UTC and are in the article on daily limits.",{"title":130,"searchDepth":276,"depth":276,"links":277},2,[278,284,285],{"id":12,"depth":276,"text":13,"children":279},[280,282,283],{"id":38,"depth":281,"text":39},3,{"id":72,"depth":281,"text":73},{"id":89,"depth":281,"text":90},{"id":140,"depth":276,"text":141},{"id":185,"depth":276,"text":186},"API and AI assistants","Get a signed webhook when a task ends, repeat a request safely with an Idempotency-Key, and read the rate limit headers.","md",{},true,15,"\u002Fhelp\u002Fapi-webhooks-idempotency-and-rate-limits",{"title":5,"description":287},"help\u002Fapi-webhooks-idempotency-and-rate-limits","eQkFe74bd22h4NlN133Odqh7DDJMm6lX4mhR0JKqJ04"]