# Start a batch (/docs/api-reference/batches/create)

> Renders one template for many payloads.

`POST https://druckling-nine.vercel.app/v1/batches`

Renders one template for many payloads. Every item's `data` is validated first: if any item is invalid nothing is rendered and the answer is 422 with `data.errors` listing the first invalid items' `index`, `field` and `message` (`data.invalidItems` counts them all). Otherwise each item becomes an asynchronous document (its `batch` set) and the answer is 202. Poll `GET /batches/{id}` or subscribe to `batch.completed`; a completed batch has a `zip_url` with every rendered PDF. Up to 1,000 items and 4 MB per request. Live batches must fit in the plan's documents left today and this month (429 `quota_exceeded`).

## Request body (JSON Schema)

```json
{
  "type": "object",
  "properties": {
    "template": {
      "type": "string",
      "description": "Template slug, e.g. invoice-standard"
    },
    "version": {
      "anyOf": [
        {
          "type": "integer",
          "minimum": -9007199254740991,
          "maximum": 9007199254740991,
          "exclusiveMinimum": 0
        },
        {
          "const": "latest"
        }
      ],
      "description": "Pinned version or `latest` (default)."
    },
    "items": {
      "type": "array",
      "minItems": 1,
      "maxItems": 1000,
      "items": {
        "type": "object",
        "properties": {
          "data": {
            "type": "object",
            "propertyNames": {
              "type": "string"
            },
            "additionalProperties": {},
            "description": "Payload matching the template schema."
          },
          "filename": {
            "type": "string",
            "maxLength": 200,
            "description": "File name of this item's PDF; overrides `filename_pattern`."
          },
          "language": {
            "type": "string",
            "maxLength": 35,
            "description": "This item's language; overrides the batch's `language`."
          }
        },
        "required": [
          "data"
        ]
      }
    },
    "language": {
      "type": "string",
      "maxLength": 35,
      "description": "Language of every item without its own `language`: one of the template's `languages` (default: its default language). Unknown languages are rejected with 422 on `language` or `items.{n}.language`."
    },
    "filename_pattern": {
      "type": "string",
      "maxLength": 200,
      "description": "File names from each item's data, e.g. `invoice-{{invoice.number}}.pdf`. Names are made unique within the batch; default `{template}-{n}.pdf`. XRechnung and Peppol templates produce XML e-invoices, named `.xml`."
    },
    "storage": {
      "anyOf": [
        {
          "type": "object",
          "properties": {
            "bucket": {
              "type": "string",
              "minLength": 1,
              "maxLength": 64,
              "description": "A bucket id from the Storage page, or `default` for the workspace's default bucket."
            }
          },
          "required": [
            "bucket"
          ]
        },
        {
          "const": false
        }
      ],
      "description": "Copy every item's file to one of your own buckets, as for a single render."
    }
  },
  "required": [
    "template",
    "items"
  ]
}
```

## Response 202: OK

```json
{
  "type": "object",
  "properties": {
    "id": {
      "type": "string"
    },
    "object": {
      "const": "batch"
    },
    "status": {
      "enum": [
        "queued",
        "running",
        "completed",
        "failed",
        "canceled"
      ],
      "type": "string",
      "description": "`queued` → `running` → `completed` (ZIP ready), `failed` (nothing rendered, or the ZIP couldn't be built) or `canceled`."
    },
    "template": {
      "type": "string"
    },
    "version": {
      "type": "number"
    },
    "filename_pattern": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ]
    },
    "counts": {
      "type": "object",
      "properties": {
        "total": {
          "type": "number"
        },
        "pending": {
          "type": "number"
        },
        "rendered": {
          "type": "number"
        },
        "failed": {
          "type": "number"
        },
        "canceled": {
          "type": "number"
        }
      },
      "required": [
        "total",
        "pending",
        "rendered",
        "failed",
        "canceled"
      ],
      "description": "Items by outcome; `pending` is queued or rendering."
    },
    "zip_url": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "description": "Signed download URL of the ZIP with every rendered file (PDFs, or XML e-invoices), once the batch completed and while the ZIP is retained."
    },
    "zip_size_bytes": {
      "anyOf": [
        {
          "type": "number"
        },
        {
          "type": "null"
        }
      ]
    },
    "zip_expires_at": {
      "anyOf": [
        {
          "type": "string",
          "format": "date-time"
        },
        {
          "type": "null"
        }
      ],
      "description": "When the ZIP is deleted (the file retention period)."
    },
    "error": {
      "anyOf": [
        {
          "type": "object",
          "properties": {
            "code": {
              "type": "string"
            },
            "message": {
              "type": "string"
            }
          },
          "required": [
            "code",
            "message"
          ]
        },
        {
          "type": "null"
        }
      ]
    },
    "test_mode": {
      "type": "boolean"
    },
    "created_at": {
      "type": "string",
      "format": "date-time"
    },
    "finished_at": {
      "anyOf": [
        {
          "type": "string",
          "format": "date-time"
        },
        {
          "type": "null"
        }
      ]
    }
  },
  "required": [
    "id",
    "object",
    "status",
    "template",
    "version",
    "filename_pattern",
    "counts",
    "zip_url",
    "zip_size_bytes",
    "zip_expires_at",
    "error",
    "test_mode",
    "created_at",
    "finished_at"
  ]
}
```