Webhooks
Use callback_url in the ModelGo Unified Video API to receive a notification when a task finishes. Check that the site offers a model on the unified video protocol and that its public key endpoint returns an active key. If keys is empty, poll the task endpoint for results. You can also query the task after a failed webhook delivery.
Events
type | When |
|---|---|
video.generation.completed | The video is ready (data.status is completed) |
video.generation.failed | The task failed, expired or could not be confirmed; data.error.code says which |
Each task sends one event, when it reaches its final state.
Request
POST /modelgo/video HTTP/1.1
Host: hooks.example.com
Content-Type: application/json
User-Agent: ModelGo-Webhook/1.0
X-ModelGo-Event-Id: evt_170bd86b-c8a7-4ba7-b9ef-97df70a9822b
X-ModelGo-Event-Type: video.generation.completed
X-ModelGo-Delivery-Attempt: 1
X-ModelGo-Timestamp: 1794909759
X-ModelGo-Signature: ed25519=<base64 signature>
X-ModelGo-Signature-Key-Id: <kid>
{
"id": "evt_170bd86b-c8a7-4ba7-b9ef-97df70a9822b",
"type": "video.generation.completed",
"created_at": 1794909759,
"workspace_id": "<your workspace ID>",
"data": { "...": "the task object, identical to GET /v1/videos/{task_id}" }
}datais the task object exactly asGET /v1/videos/{task_id}returned it when the task finished.workspace_idis the workspace the task belongs to; the console shows it as the workspace ID.- Answer with any
2xxwithin 10 seconds and do the work afterwards.
Verify the signature
Every delivery is signed with a ModelGo Ed25519 key. To accept one:
- Read the raw request body as bytes, before parsing the JSON: the signature covers the exact bytes sent.
- Reject it if
X-ModelGo-Timestampis more than 5 minutes away from your clock. - Take the public key whose
kidmatchesX-ModelGo-Signature-Key-Idfrom the public keys; cache them and fetch again when akidis unknown. - Verify the
ed25519=entry ofX-ModelGo-Signature(base64) over"{X-ModelGo-Timestamp}.{raw body}". - Check that
workspace_idis your workspace and thatdata.idis a task you created. One platform key signs for every workspace, so this is how you recognize an event another ModelGo customer forwarded to your address. - Deduplicate on
X-ModelGo-Event-Id: the same event can arrive more than once.
The signature entry is named after its algorithm, ed25519=. It is not the v1= HMAC-SHA256 signature of Stripe-style webhooks, so verification code written for those does not apply.
Public keys
curl https://api.modelgo.ai/v1/webhooks/signing-keys{
"keys": [
{
"kty": "OKP",
"crv": "Ed25519",
"alg": "EdDSA",
"use": "sig",
"kid": "<kid>",
"x": "<base64url public key>",
"status": "active",
"public_key_pem": "-----BEGIN PUBLIC KEY-----\n…\n-----END PUBLIC KEY-----\n"
}
]
}- No API key is needed. The response is a JWKS (RFC 8037):
xis the raw 32-byte public key in base64url, andpublic_key_pemis the same key as SPKI PEM. - Use the
activekey to verify new deliveries. After rotation, aretiredkey stays listed for a while for verification. - Each site has its own keys: use the keys of the site you call (
https://api.modelgo.ai).
Examples
Python (pip install cryptography):
import base64
import json
import time
from cryptography.exceptions import InvalidSignature
from cryptography.hazmat.primitives.serialization import load_pem_public_key
def verify_modelgo_webhook(raw_body: bytes, headers, keys_by_kid, my_workspace_id):
"""Return the event if the delivery is genuine and meant for my workspace, else None."""
timestamp = headers["X-ModelGo-Timestamp"]
if abs(time.time() - int(timestamp)) > 300:
return None
key = keys_by_kid.get(headers["X-ModelGo-Signature-Key-Id"])
if key is None:
return None # unknown kid: refresh the keys and try again
public_key = load_pem_public_key(key["public_key_pem"].encode())
message = timestamp.encode() + b"." + raw_body
for entry in headers["X-ModelGo-Signature"].split(","):
scheme, _, value = entry.strip().partition("=")
if scheme != "ed25519":
continue
try:
public_key.verify(base64.b64decode(value), message)
except (InvalidSignature, ValueError):
continue
event = json.loads(raw_body)
return event if event["workspace_id"] == my_workspace_id else None
return NoneNode.js (built-in crypto; in Express, read the body with express.raw({ type: 'application/json' })):
import crypto from 'node:crypto'
// keysByKid: { [kid]: key } built from GET /v1/webhooks/signing-keys
// rawBody: the request body as a Buffer, before JSON parsing
export function verifyModelGoWebhook(rawBody, headers, keysByKid, myWorkspaceId) {
const timestamp = headers['x-modelgo-timestamp']
if (!timestamp || Math.abs(Date.now() / 1000 - Number(timestamp)) > 300) return null
const key = keysByKid[headers['x-modelgo-signature-key-id']]
if (!key) return null // unknown kid: refresh the keys and try again
const publicKey = crypto.createPublicKey(key.public_key_pem)
const message = Buffer.concat([Buffer.from(`${timestamp}.`), rawBody])
for (const entry of (headers['x-modelgo-signature'] || '').split(',')) {
const [scheme, value = ''] = entry.trim().split(/=(.*)/s)
if (scheme !== 'ed25519') continue
if (crypto.verify(null, message, publicKey, Buffer.from(value, 'base64'))) {
const event = JSON.parse(rawBody)
return event.workspace_id === myWorkspaceId ? event : null
}
}
return null
}Go (standard library):
import (
"crypto/ed25519"
"crypto/x509"
"encoding/base64"
"encoding/json"
"encoding/pem"
"errors"
"net/http"
"strconv"
"strings"
"time"
)
// PublicKeyFromPEM parses a public_key_pem from GET /v1/webhooks/signing-keys.
func PublicKeyFromPEM(s string) (ed25519.PublicKey, error) {
block, _ := pem.Decode([]byte(s))
if block == nil {
return nil, errors.New("no PEM block")
}
key, err := x509.ParsePKIXPublicKey(block.Bytes)
if err != nil {
return nil, err
}
pub, ok := key.(ed25519.PublicKey)
if !ok {
return nil, errors.New("not an Ed25519 key")
}
return pub, nil
}
type Event struct {
ID string `json:"id"`
Type string `json:"type"`
CreatedAt int64 `json:"created_at"`
WorkspaceID string `json:"workspace_id"`
Data json.RawMessage `json:"data"`
}
// Verify returns the event when the delivery is genuine and meant for my workspace.
func Verify(rawBody []byte, h http.Header, keysByKid map[string]ed25519.PublicKey, myWorkspaceID string) (*Event, bool) {
timestamp := h.Get("X-ModelGo-Timestamp")
ts, err := strconv.ParseInt(timestamp, 10, 64)
if err != nil || time.Since(time.Unix(ts, 0)).Abs() > 5*time.Minute {
return nil, false
}
pub, ok := keysByKid[h.Get("X-ModelGo-Signature-Key-Id")]
if !ok {
return nil, false // unknown kid: refresh the keys and try again
}
msg := append([]byte(timestamp+"."), rawBody...)
for _, entry := range strings.Split(h.Get("X-ModelGo-Signature"), ",") {
scheme, value, _ := strings.Cut(strings.TrimSpace(entry), "=")
sig, err := base64.StdEncoding.DecodeString(value)
if scheme != "ed25519" || err != nil || !ed25519.Verify(pub, msg, sig) {
continue
}
var ev Event
if json.Unmarshal(rawBody, &ev) != nil || ev.WorkspaceID != myWorkspaceID {
return nil, false
}
return &ev, true
}
return nil, false
}Java has Ed25519 built in from JDK 15 (Signature.getInstance("Ed25519") with the PEM body as an X509EncodedKeySpec); earlier versions need a library such as Bouncy Castle.
Delivery and retries
| Your endpoint answers | Result |
|---|---|
2xx | Delivered |
410 Gone | Stopped: the event is not sent again |
| Anything else, no answer within 10 seconds, or no connection | Retried after 1 minute, 5 minutes, 15 minutes, 1 hour, 3 hours, 6 hours and 12 hours — 8 attempts over about 22 hours — then dropped |
- Each attempt is signed again with a new timestamp;
X-ModelGo-Delivery-Attemptcounts the attempts. - Redirects are not followed: a
3xxcounts as a failed attempt. - Delivery is at least once: deduplicate on
X-ModelGo-Event-Id. - An event that is never delivered does not affect the task or its billing; query
GET /v1/videos/{task_id}instead.
Callback URL requirements
https, at most 2048 characters, no username or password in the URL.- The host must be a domain name, not an IP address; the port must be 443 or 8443.
- The address must resolve to a public IP address: deliveries to private, loopback or link-local addresses are refused.
- The URL is used only to deliver ModelGo's event; it is never passed to a supplier.