Create a webhook endpoint

POSThttps://api.mozartai.com/v1/webhooks

Registers an https address that Mozart calls when a job becomes playable, succeeds, fails or is cancelled.

Cost
Free
Rate limit
Write
Idempotency key
Optional
CLI (coming soon)
mozart webhooks create

When to use: A program that runs many jobs wants to be told when each ends instead of checking. Pass url and event_types. Store secret from the answer: it is shown once and signs every delivery.

When not to use: For one job in a conversation, call POST /v1/jobs/wait instead; it needs no server of your own.

Side effects: Creates a webhook endpoint that receives events for every job of the user. A repeat call without the same idempotency key registers a second endpoint and doubles deliveries.

Authentication

Send your API key as Authorization: Bearer <key>. The key needs these scopes:

  • webhooks:manage

Headers

  • idempotency-keystringOptional1 to 255 characters

    A unique string per intended action. Repeating a call with the same key returns the first answer instead of doing the work twice: a key is bound to its first request for 90 days; its response is replayed for 24 hours; use a new key for a new request.

Request body

  • urlstring (uri)Required
  • descriptionstringOptionalat most 200 characters
  • event_typeslist of enumRequiredat least 1 items
    Allowed values
    • job.playable
    • job.succeeded
    • job.failed
    • job.cancelled

Response 201

Success.

  • idstringRequired
  • objectconstantRequired
  • urlstringRequired
  • descriptionstringor nullRequired
  • event_typeslist of enumRequired
    Allowed values
    • job.playable
    • job.succeeded
    • job.failed
    • job.cancelled
  • statusenumRequired
    Allowed values
    • active
    • disabled
  • secretstringor nullRequired
  • created_atstringRequired

Response headers

  • x-request-idThe id of this request; quote it when asking for help.
  • x-mozart-api-versionThe API version that answered.
  • x-ratelimit-limitRequests allowed in the current window for this caller.
  • x-ratelimit-remainingRequests left in the current window.
  • x-ratelimit-resetWhen the window resets, in Unix seconds.
  • idempotent-replayedtrue when this answer is the stored answer to an earlier call with the same idempotency key; the work was not done again.

Verify webhook deliveries

Every delivery is signed with the Standard Webhooks scheme. It carries webhook-id, webhook-timestamp and webhook-signature headers. Sign {webhook-id}.{webhook-timestamp}.{raw body} with HMAC SHA-256, using the base64 key after the whsec_ prefix of the secret that POST /v1/webhooks returned once. Compare the base64 result with each space-separated v1,<signature> entry in constant time, and refuse a timestamp more than five minutes old. Read the raw body before parsing it.

cURL
KEY=$(printf %s "$MOZART_WEBHOOK_SECRET" | sed 's/^whsec_//' | base64 -d | xxd -p -c 256)
EXPECTED=$(printf "%s.%s.%s" "$WEBHOOK_ID" "$WEBHOOK_TIMESTAMP" "$(cat body.json)" \
  | openssl dgst -sha256 -mac HMAC -macopt hexkey:$KEY -binary | base64)
echo "$WEBHOOK_SIGNATURE" | tr " " "\n" | grep -qx "v1,$EXPECTED" && echo valid

Errors

What to do: PUBLIC_API_URL_NOT_ALLOWED: use a public https address. PUBLIC_API_WEBHOOK_ENDPOINT_LIMIT_REACHED: delete an endpoint with DELETE /v1/webhooks/{webhook_id} first. PUBLIC_API_SCOPE_MISSING: the key lacks webhooks:manage.

StatusTypeMeaning
400invalid_requestThe request is malformed or an input is invalid.
401authenticationThe key or token is missing, invalid or revoked.
402insufficient_creditsThe account has too few credits for this call. A REST key also needs an API plan (Starter, Build, Scale or Growth) or API credits; with neither, every call is refused with PUBLIC_API_CREDITS_REQUIRED. payment_required: The account's plan does not include this; it needs an upgrade.
403permissionThe caller may not do this: a missing scope, a Mozart CLI sign-in whose account is below Pro, or access not enabled.
404not_foundThe resource or route does not exist for this caller.
409conflictThe request conflicts with the current state, or an idempotency key was reused with a different body.
422content_refusedThe input was refused by content screening.
429rate_limitedToo many requests; retry after Retry-After seconds. limit_reached: A daily, concurrent or total limit was reached.
500internalMozart failed to answer; retry later.
503provider_unavailableA generation provider is unavailable; retry later. service_unavailable: A Mozart check the request needs, such as content screening, is temporarily unavailable; retry after retry_after_seconds.