APIs
Webhooks
Have Minu call your server when a task ends. Events, the payload, how to verify the signature, and how failed deliveries are retried.
Esta página aún no está traducida. Se muestra la versión en inglés.
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 endpoint | callback_url on a task | |
|---|---|---|
| Set up | Once, in the console under Webhooks | In the body of POST /v1/tasks |
| Receives | The events you chose, for every task of the organization | The final event of that one task |
| Good for | One handler for all your traffic | A 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:
| Event | Sent when |
|---|---|
task.succeeded | Every requested result was delivered. |
task.partially_succeeded | Some of the requested results were delivered. |
task.failed | The task ended without a result. |
task.canceled | The task was canceled while it was queued. |
task.expired | The 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
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{
"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
}
}| Field | Description |
|---|---|
id | Identifier of the event. The same value as the minu-webhook-id header. |
type | The event type. |
created_at | When this delivery was sent, in Unix seconds. |
data | The task object, exactly as GET /v1/tasks/{id} returns it. |
| Header | Description |
|---|---|
minu-webhook-id | Identifier of the event. It stays the same when a delivery is retried or resent, so use it to recognise duplicates. |
minu-webhook-timestamp | When this attempt was sent, in Unix seconds. |
minu-signature | v1= 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:
- Take the
minu-webhook-idheader, theminu-webhook-timestampheader and the raw request body, the bytes exactly as received. - Compute HMAC-SHA256 over
id.timestamp.body, the three joined with full stops, using the whole secret (includingwhsec_) as the key. Encode the result as lower-case hex. - Compare it with the value after
v1=inminu-signature, using a constant-time comparison. - 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);import hashlib
import hmac
import os
import time
from flask import Flask, request
app = Flask(__name__)
SECRET = os.environ["MINU_WEBHOOK_SECRET"].encode() # whsec_…
TOLERANCE_SECONDS = 300
def verify(headers, raw_body: bytes) -> bool:
event_id = headers.get("minu-webhook-id", "")
timestamp = headers.get("minu-webhook-timestamp", "")
signatures = headers.get("minu-signature", "").split(",")
if not event_id or not timestamp.isdigit():
return False
# Refuse old deliveries, so a captured request cannot be replayed later.
if abs(time.time() - int(timestamp)) > TOLERANCE_SECONDS:
return False
signed = f"{event_id}.{timestamp}.".encode() + raw_body
expected = hmac.new(SECRET, signed, hashlib.sha256).hexdigest()
# During a secret rotation there is one signature per active secret; any match is enough.
for entry in signatures:
version, _, value = entry.strip().partition("=")
if version == "v1" and hmac.compare_digest(value, expected):
return True
return False
@app.post("/hooks/minu")
def minu_webhook():
raw_body = request.get_data() # the exact bytes that were signed
if not verify(request.headers, raw_body):
return "invalid signature", 400
event = request.get_json()
if event["type"] == "task.succeeded":
print(event["data"]["id"], event["data"]["outputs"])
return "", 200Rotate 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
2xxstatus 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.
| Attempt | Sent |
|---|---|
| 1 | Immediately |
| 2 | 30 seconds after attempt 1 |
| 3 | 2 minutes after attempt 2 |
| 4 | 10 minutes after attempt 3 |
| 5 | 30 minutes after attempt 4 |
| 6 | 2 hours after attempt 5 |
| 7 | 6 hours after attempt 6 |
| 8 | 24 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-idvalues 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.