Vai al contenuto
Documentazione:Webhooks

API

Webhooks

Have Minu call your server when a task ends. Events, the payload, how to verify the signature, and how failed deliveries are retried.

Questa pagina non è ancora stata tradotta. Viene mostrata la versione inglese.

A webhook is an HTTP POST that Minu sends to your server when a task reaches a final status. It replaces polling: you create the task, and the result comes to you.

Two ways to receive events

Webhook endpointcallback_url on a task
Set upOnce, in the console under WebhooksIn the body of POST /v1/tasks
ReceivesThe events you chose, for every task of the organizationThe final event of that one task
Good forOne handler for all your trafficA different URL per task, tenant or environment

You can use both. A task with a callback_url in an organization that also has an endpoint produces one delivery to each.

Every URL must use https on the standard port, must be reachable from the public internet, and must not contain a user name or password.

Events

One event is sent per task, when the task ends. The event type is task. followed by the final status:

EventSent when
task.succeededEvery requested result was delivered.
task.partially_succeededSome of the requested results were delivered.
task.failedThe task ended without a result.
task.canceledThe task was canceled while it was queued.
task.expiredThe task did not finish in time.

An endpoint receives only the event types you select for it. A callback_url receives whichever of the five applies.

The console can also send a ping event to an endpoint, to test it. Answer 2xx to event types you do not handle; do not treat them as errors.

The request

HTTP
POST /hooks/minu HTTP/1.1
content-type: application/json
user-agent: Minu-Webhooks/1
minu-webhook-id: evt_1k8r2m4p0v6x8z0b2d4f6h8k
minu-webhook-timestamp: 1796169672
minu-signature: v1=5f2b8c1e9a4d7f3b6c0e8a2d4f6b9c1e3a5d7f9b2c4e6a8d0f1b3c5e7a9d2f4b
JSON
{
  "id": "evt_1k8r2m4p0v6x8z0b2d4f6h8k",
  "type": "task.succeeded",
  "created_at": 1796169672,
  "data": {
    "id": "task_1k8r2m4p0a7c9e3g5j6n8q2s",
    "object": "task",
    "model": "google/veo-3.1-fast",
    "status": "succeeded",
    "input": { "prompt": "A slow dolly shot through a bamboo forest in morning fog" },
    "outputs": [
      { "index": 0, "type": "video", "url": "https://…", "mime": "video/mp4", "bytes": 5120733 }
    ],
    "error": null,
    "estimated_cost_usd": "0.250000",
    "cost_usd": "0.250000",
    "metadata": { "order_id": "8421" },
    "created_at": 1796169600,
    "started_at": 1796169602,
    "completed_at": 1796169671
  }
}
FieldDescription
idIdentifier of the event. The same value as the minu-webhook-id header.
typeThe event type.
created_atWhen this delivery was sent, in Unix seconds.
dataThe task object, exactly as GET /v1/tasks/{id} returns it.
HeaderDescription
minu-webhook-idIdentifier of the event. It stays the same when a delivery is retried or resent, so use it to recognise duplicates.
minu-webhook-timestampWhen this attempt was sent, in Unix seconds.
minu-signaturev1= followed by the signature in hex. See below.

Verify the signature

Anyone who learns your URL can post to it. The signature proves that a request came from Minu and that its body was not changed.

Get a signing secret. In the console, under Webhooks, create the signing secret of your organization. It starts with whsec_ and is shown once; store it like an API key. Deliveries are signed from then on. One secret signs deliveries to every endpoint and every callback_url of the organization.

Check each request:

  1. Take the minu-webhook-id header, the minu-webhook-timestamp header and the raw request body, the bytes exactly as received.
  2. Compute HMAC-SHA256 over id.timestamp.body, the three joined with full stops, using the whole secret (including whsec_) as the key. Encode the result as lower-case hex.
  3. Compare it with the value after v1= in minu-signature, using a constant-time comparison.
  4. Reject the request if the timestamp is more than a few minutes from your own clock. That stops a captured request from being replayed later.

minu-signature can hold several signatures separated by commas, such as v1=…,v1=…. That happens for 24 hours after you rotate the secret, when deliveries are signed with both the previous and the new secret. Accept the request if any one of them matches.

import crypto from 'node:crypto';
import express from 'express';

const app = express();
const secret = process.env.MINU_WEBHOOK_SECRET; // whsec_…
const TOLERANCE_SECONDS = 300;

function verify(headers, rawBody) {
  const id = headers['minu-webhook-id'];
  const timestamp = headers['minu-webhook-timestamp'];
  const signatures = String(headers['minu-signature'] ?? '').split(',');
  if (!id || !timestamp) return false;

  // Refuse old deliveries, so a captured request cannot be replayed later.
  if (Math.abs(Date.now() / 1000 - Number(timestamp)) > TOLERANCE_SECONDS) return false;

  const expected = crypto.createHmac('sha256', secret).update(`${id}.${timestamp}.`).update(rawBody).digest();

  // During a secret rotation there is one signature per active secret; any match is enough.
  return signatures.some((entry) => {
    const [version, hex] = entry.trim().split('=');
    if (version !== 'v1' || !hex) return false;
    const given = Buffer.from(hex, 'hex');
    return given.length === expected.length && crypto.timingSafeEqual(given, expected);
  });
}

// express.raw keeps the body as the exact bytes that were signed.
app.post('/hooks/minu', express.raw({ type: 'application/json' }), (request, response) => {
  if (!verify(request.headers, request.body)) {
    return response.status(400).send('invalid signature');
  }

  const event = JSON.parse(request.body.toString('utf8'));

  // Acknowledge first, then do the work: Minu waits 10 seconds for an answer.
  response.sendStatus(200);

  if (event.type === 'task.succeeded') {
    console.log(event.data.id, event.data.outputs);
  }
});

app.listen(3000);

Rotate the secret

An owner or an admin can rotate the signing secret in the console. The new secret is shown once. For the next 24 hours every delivery carries two signatures, one for each secret, so you can deploy the new secret at any moment in that window without rejecting a single delivery. After 24 hours only the new secret signs.

Answer quickly

  • Answer with any 2xx status within 10 seconds. Anything else, including a redirect, counts as a failed attempt. Redirects are not followed.
  • Do slow work after you have answered: put the event on a queue, or start a background job.
  • The body of your answer is ignored.

Retries

A delivery that fails is retried on a fixed schedule: 8 attempts in all, over about 33 hours.

AttemptSent
1Immediately
230 seconds after attempt 1
32 minutes after attempt 2
410 minutes after attempt 3
530 minutes after attempt 4
62 hours after attempt 5
76 hours after attempt 6
824 hours after attempt 7

Each attempt is signed afresh, with its own timestamp. When the eighth attempt fails, the delivery is marked failed and is not sent again on its own.

An endpoint that keeps failing is switched off. After 20 deliveries in a row have failed all their attempts, the endpoint is disabled and receives nothing more until you enable it again in the console. One successful delivery resets the count.

Handle duplicates and order

  • The same event can arrive more than once: a retry after your answer was lost, or a resend from the console. Record the minu-webhook-id values you have processed and skip the ones you have seen.
  • Events of different tasks can arrive in any order. Use the task in data, not the order of arrival, as the truth.
  • If you are ever unsure, GET /v1/tasks/{id} returns the current task.

Inspect and resend deliveries

The console lists every delivery under Webhooks: its event, its destination, how many attempts were made and the status your server answered with. From there you can send a ping to test an endpoint and resend any delivery, for example after fixing a bug in your handler. A resend is a new delivery of the same event, with the same minu-webhook-id. The task page under Logs shows the deliveries of that task.

Callbacks for kie.ai-style tasks

Tasks created through the kie.ai-compatible routes send their callback in kie.ai's format and with kie.ai's signature headers, not the ones on this page. They go to the task's callBackUrl only.