Skip to main content
Webhooks provide instant notifications when your image generation tasks complete, fail, or timeout. No more polling!

Setup Guide

1

Create Webhook Endpoint

Set up an HTTPS endpoint that can receive POST requests.
from flask import Flask, request, jsonify

app = Flask(__name__)

@app.route('/webhook/chatgpt-images', methods=['POST'])
def handle_webhook():
    data = request.json
    
    if data['status'] == 'completed':
        print(f"Image ready: {data['result_image_url']}")
    else:
        print(f"Generation failed: {data.get('message')}")
        
    return jsonify({'status': 'received'}), 200
2

Add Webhook URL

Include your webhook URL when creating a generation task.
curl -X POST https://platform.runblob.io/v1/chatgpt-images/generate -H "Authorization: Bearer YOUR_API_KEY" -H "Content-Type: application/json" -d '{
  "prompt": "A beautiful landscape",
  "callback_url": "https://your-app.com/webhook/chatgpt-images"
}'
3

Handle Notifications

Your endpoint will receive instant notifications when tasks complete.

Payload Structure

Sent when image generation completes successfully.
{
  "task_uuid": "dc62d83d-1953-4bca-8554-222679a7a4a9",
  "status": "completed",
  "prompt": "cat and dog",
  "result_image_url": "https://cdn.example.com/images/dc62d83d.png",
  "message": null
}
status
string
Always "completed" for successful generations
task_uuid
string
UUID of the completed task
result_image_url
string
Direct download URL for the generated image
prompt
string
Original prompt used for generation
message
null
Always null for successful generations

Reliability Features

Retry Policy: Up to 5 attempts with 30-second intervalsBackoff Strategy: Linear backoff between retriesFailure Handling: After 5 failed attempts, the webhook is marked as failed
Request Timeout: 30 seconds per webhook requestConnection Timeout: 10 seconds to establish connectionBest Practice: Respond quickly with a 200 status code
HTTPS Required: All webhook URLs must use HTTPSIP Allowlist: Consider restricting access to RunBlob’s IP rangesValidation: Always validate the task_uuid in your webhook handler

Example Implementations

from flask import Flask, request, jsonify
import logging

app = Flask(__name__)
logging.basicConfig(level=logging.INFO)

@app.route('/webhook/chatgpt-images', methods=['POST'])
def chatgpt_images_webhook():
    try:
        data = request.json
        task_uuid = data.get('task_uuid')
        status = data.get('status')
        
        if status == 'completed':
            image_url = data.get('result_image_url')
            logging.info(f"Image ready for {task_uuid}: {image_url}")
            # Process successful generation
            process_image(task_uuid, image_url)
        else:
            error_code = data.get('message')
            logging.error(f"Generation failed for {task_uuid}: {error_code}")
            # Handle failure
            handle_failure(task_uuid, error_code)
        
        return jsonify({'status': 'received'}), 200
    except Exception as e:
        logging.error(f"Webhook error: {str(e)}")
        return jsonify({'error': 'Internal error'}), 500

def process_image(task_uuid, image_url):
    # Your image processing logic here
    pass

def handle_failure(task_uuid, error_code):
    # Your error handling logic here
    pass
Important: Always return a 200 status code quickly to acknowledge receipt. Perform heavy processing asynchronously to avoid timeouts.