Webhooks
Recevez des notifications en temps réel lors de la réussite ou de l'échec des tâches.
Vue d'ensemble
Webhooks allow you to receive HTTP callbacks when your image or video generation tasks complete. Instead of polling for results, you can set up a webhook endpoint to receive automatic notifications.
Événements disponibles
- job.completedTriggered when a task completes successfully
- job.failedTriggered when a task fails
Points d'accès API
GET
/api/v1/webhooksList all your webhook configurations
Exemple de réponse:
{
"success": true,
"data": [
{
"id": 1,
"url": "https://your-server.com/webhook",
"events": ["job.completed", "job.failed"],
"status": "active"
}
]
}POST
/api/v1/webhooksCreate a new webhook endpoint
Exemple de Demande:
{
"url": "https://your-server.com/webhook",
"events": ["job.completed", "job.failed"],
"secret_key": "your-secret-key"
}Paramètres:
| Paramètre | Type | Obligatoire | Description |
|---|---|---|---|
| url | string | Obligatoire | Your webhook endpoint URL |
| events | string[] | Obligatoire | Events to subscribe to |
| secret_key | string | Facultatif | Secret for signature verification |
Exemple de réponse:
{
"success": true,
"data": {
"id": 1,
"url": "https://your-server.com/webhook",
"events": ["job.completed", "job.failed"],
"status": "active"
}
}DELETE
/api/v1/webhooks/{id}Delete a webhook endpoint
Exemple de réponse:
{
"success": true,
"data": { "id": 1 }
}Contenu du Webhook
Format des notifications webhook envoyées à votre point de terminaison
| En-tête | Description |
|---|---|
| X-Nano-Timestamp | Unix timestamp of the request |
| X-Nano-Signature | HMAC-SHA256 signature for verification |
Exemple de Chargement Utile:
{
"event": "job.completed",
"task_id": "task_xxx",
"task_type": "image",
"status": "completed",
"data": {
"url": "https://cdn.example.com/image.png",
"credits_charged": 6
},
"timestamp": "2024-12-23T10:00:00Z"
}Vérification de signature
const crypto = require('crypto');
function verifySignature(payload, signature, secret, timestamp) {
const message = `${timestamp}.${JSON.stringify(payload)}`;
const expectedSig = crypto
.createHmac('sha256', secret)
.update(message)
.digest('hex');
return `v1=${expectedSig}` === signature;
}