Leum chun t-susbaint
Stiùireadh API

Webhooks

Seall mar Markdown Air ùrachadh

An àite bhòtadh tric, thoir webhook_url do ruith. Nuair a ruigeas an t-iarrtas inbhe dheireannach (succeeded, failed no canceled), cuiridh sinn POST le ainm-sgrìobhte chun URL sin.

uidhe ⚠️
curl -X POST "https://api.doitong.com/v1/run/{model_id}?webhook_url=https://example.com/hooks/doitong" \
  -H "Authorization: Bearer $DOITONG_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"prompt": "..."}'

An tachartas

Bannan-cinn an iarrtais
POST /hooks/doitong HTTP/1.1
Content-Type: application/json
User-Agent: Doitong-Webhooks/1
Doitong-Request-Id: req_8k2m4q7x1z9c3v5b6n0p2r4t
Doitong-Signature: t=1760961609,v1=5f1c0d6e2b…
Corp an iarrtais
{
  "id": "evt_8k2m4q7x1z9c3v5b6n0p2r4t_succeeded",
  "object": "event",
  "type": "request.succeeded",
  "created_at": "2026-10-20T12:00:09Z",
  "data": {
    "id": "req_8k2m4q7x1z9c3v5b6n0p2r4t",
    "object": "request",
    "status": "succeeded",
    "outputs": [ { "type": "video", "url": "https://content.doitong.com/dev-api/…/0-output.mp4" } ]
  }
}
  • Is e type request.succeeded, request.failed no request.canceled.
  • Is e data an nì iarrtais slàn, dìreach mar a thilleas GET /requests/{id}.
  • Tha id seasmhach airson iarrtas agus an inbhe dheireannach aige. Cleachd e gus lìbhrigeadh a làimhsich thu mu thràth a leigeil seachad.

Lìbhrigidhean agus ath-oidhirpean

Freagair le inbhe 2xx sam bith taobh a-staigh 10 diogan. Thèid rud sam bith eile (no ùine-ama) ath-fheuchainn: suas ri 6 oidhirpean uile gu lèir, às dèidh 30 diog, 2 mhionaid, 10 mionaidean, 1 uair agus 6 uairean. Dèan obair shlaodach an dèidh dhut freagairt, chan ann roimhe.

Dearbhaich an t-ainm-sgrìobhte

Tha an dìomhair soidhnidh fhèin aig gach iuchair. Leugh e aon turas bho GET https://api.doitong.com/v1/account (webhook_signing_secret, tha e a’ tòiseachadh le whsec_) agus glèidh e ri taobh na h-iuchrach.

Tha bann-cinn Doitong-Signature de chruth t=<unix time>,v1=<signature>, far a bheil an t-ainm-sgrìobhte na HMAC-SHA256 hexadecimal de "<t>.<raw request body>" le do dhìomhaireachd mar an iuchair. Gus dearbhadh:

  1. Gabh na bytes den bhodhaig amh dìreach mar a fhuaireadh iad (mus tèid JSON a pharsadh).
  2. Obraich a-mach HMAC-SHA256 de t + "." + body le do dhìomhaireachd, mar hexadecimal litrichean beaga.
  3. Dèan coimeas ris an v1 ann an ùine sheasmhach.
  4. Diùlt an tachartas nuair a tha t còrr is 5 mionaidean air falbh bhon uaireadair agad (dìon an aghaidh ath-chluich).

Glacadair slàn ann an Node.js (Express) agus Python (Flask):

import crypto from "node:crypto";
import express from "express";

const SECRET = process.env.DOITONG_WEBHOOK_SECRET; // whsec_...
const app = express();

app.post("/hooks/doitong", express.raw({ type: "application/json" }), (req, res) => {
  const header = req.get("Doitong-Signature") || "";
  const parts = Object.fromEntries(header.split(",").map((p) => p.split("=", 2)));
  const t = Number(parts.t);
  const expected = crypto.createHmac("sha256", SECRET).update(t + "." + req.body).digest("hex");
  const given = Buffer.from(parts.v1 || "", "utf8");
  const valid =
    given.length === expected.length &&
    crypto.timingSafeEqual(given, Buffer.from(expected, "utf8")) &&
    Math.abs(Date.now() / 1000 - t) < 300;
  if (!valid) return res.status(400).send("bad signature");

  const event = JSON.parse(req.body);
  if (event.type === "request.succeeded") {
    console.log(event.data.id, event.data.outputs.map((o) => o.url));
  }
  res.sendStatus(204);
});

Molaidhean

  • Freagair gu luath agus cuir do ghiollachd fhèin ann an ciudha.
  • Buinidh an dìomhair don iuchair API a thòisich an ruith. Tha dìomhaireachdan eadar-dhealaichte aig iuchraichean ann an seirbheisean eadar-dhealaichte.