POST

Render a batch

One template, up to 100 sets of values, each its own render, in the background.

View as Markdown
POSThttps://api.muzekit.com/v1/renders/batch
curl -X POST https://api.muzekit.com/v1/renders/batch \
  -H "Authorization: Bearer $MUZEKIT_SECRET_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "template": "product-card", "format": "png", "items": [
        { "modifications": { "title": "Blue mug" } },
        { "modifications": { "title": "Red mug" }, "size": "1080x1920" }
      ] }'

Body

Everything Create a render takes, except modifications, which each item carries instead:

Field
items1 to 100 of { "modifications": {…}, "pages": […], "size": … }; pages and size override the batch's for that item

Every item is a render of its own, queued at once and rendered in the background, up to four at a time (videos two). The answer is 202 straight away; follow the renders with List renders and ?batch=bat_…, or the render.succeeded and render.failed webhooks.

Credits are checked for the whole batch as it's queued: when they run out, that item and the rest come back failed with api_credits_exhausted, and the items before them still render. A Test environment's daily cap (429 test_renders_exhausted) stops the rest the same way. An item that is wrong by itself, such as a bad size, fails alone.

renders lists one entry per item, in the order of items. An item that couldn't start has id: null and its item index.

Examples

Render a batch from rows of data

Turn each row of a spreadsheet or a database query into one item. Up to 100 items a request; split longer lists into several batches.

# rows.json: [{ "name": "Blue mug", "image": "https://…" }, …]
jq '{ template: "product-card", format: "png",
      items: map({ modifications: { headline: .name, photo: .image } }) }' \
  rows.json \
  | curl https://api.muzekit.com/v1/renders/batch \
      -H "Authorization: Bearer $MUZEKIT_SECRET_KEY" \
      -H "Content-Type: application/json" \
      -d @-

Follow a batch until it's done

List the batch's renders until none is queued or processing. A batch has at most 100 renders, so limit=100 gets them in one page.

curl "https://api.muzekit.com/v1/renders?batch=bat_Zb3x0k1PqLm2&limit=100" \
  -H "Authorization: Bearer $MUZEKIT_SECRET_KEY" \
  | jq -r '.data[] | "\(.id)\t\(.status)"'

The list is newest first, not in item order. Items that couldn't start aren't in it: they have no render.

Match each render to its row

Keep the render ids from the answer, in item order, next to your rows. Then each render.succeeded webhook (its data.render) or listed render finds its row.

# Item index, render id (null if it couldn't start), status
jq -r '.renders | to_entries[]
  | "\(.key)\t\(.value.id)\t\(.value.status)"' batch.json

In production, store the pairs in your database rather than in memory: renders finish after your request ends.

Response

JSON
{
  "object": "batch",
  "id": "bat_Zb3x0k1PqLm2",
  "template": "tpl_Vk1t4l9xvQv",
  "renders": [
    {
      "object": "render",
      "id": "rnd_…",
      "status": "queued",
      "outputs": [],
      "…": "…"
    },
    {
      "object": "render",
      "id": null,
      "status": "failed",
      "item": 1,
      "error": { "code": "invalid_size", "message": "…" }
    }
  ]
}