Skip to Content
Webhooks

Webhooks

What are Webhooks?

Webhooks allow you to receive real-time notifications when your tasks are completed. Instead of repeatedly polling the API for task status, Pixwith.AI will automatically send a POST request to your specified URL when results are ready.

How to Configure

Step 1: Set Your Webhook URL

  1. Log in to your Pixwith.AI Dashboard 
  2. Navigate to the API section
  3. Enter your webhook endpoint URL in the Webhook URL field
  4. Click Save

Step 2: Create Your Endpoint

const express = require('express'); const app = express(); app.use(express.json()); app.post('/webhook', (req, res) => { const { code, message, data } = req.body; const { task_id, task_type, status, result_urls } = data; if (status === 2) { // Task completed successfully console.log('Task completed:', task_id); console.log('Results:', result_urls); } else if (status === 3) { // Task failed console.log('Task failed:', task_id); } res.status(200).send('OK'); }); app.listen(3000);

Webhook Structure

When a task completes, Pixwith.AI sends a POST request with the following JSON payload:

Successful Task

{ "code": 1, "message": "success", "data": { "task_id": "d425ab4dc256f0ebaa84862b9cea8a3d", "task_type": "t2i", "status": 2, "result_urls": [ "https://cdn.pixwithapi.online/d425ab4dc256f0ebaa84862b9cea8a3d_0.png", "https://cdn.pixwithapi.online/d425ab4dc256f0ebaa84862b9cea8a3d_1.png" ] } }

Failed Task

{ "code": 1, "message": "success", "data": { "task_id": "d425ab4dc256f0ebaa84862b9cea8a3d", "task_type": "t2i", "status": 3, "result_urls": [] } }

Fields Description

FieldTypeDescription
codeintegerResponse code: 1 (success)
messagestringResponse message
data.task_idstringUnique identifier for the task
data.task_typestringTask type: t2i (text to image), i2i (image to image), t2v (text to video), i2v (image to video)
data.statusintegerTask status: 2 (completed), 3 (failed)
data.result_urlsarrayArray of generated media URLs (empty when status is 3)

Note: Your webhook endpoint must respond with a 200 OK status code within 5 seconds.

Last updated on