# API reference (/docs/api-reference)

> Conventions of the Druckling REST API, and a reference for every endpoint generated from the API's own contract.

The Druckling API is a JSON REST API. Every endpoint in this section is generated from the same contract the API is served from, so field names, types and limits here always match what `/v1` accepts. Use the playground on each page to send a request with your test key.

## Base URL [#base-url]

```text
https://druckling-nine.vercel.app/v1
```

All endpoints are versioned under `/v1`. Requests and responses use JSON (`Content-Type: application/json`) with `snake_case` field names, and timestamps are ISO 8601 strings in UTC.

## Authentication [#authentication]

Send an API key with every request, either as a bearer token or in the `x-api-key` header:

```bash tab="Bearer"
curl https://druckling-nine.vercel.app/v1/templates \
  -H "Authorization: Bearer $DRUCKLING_API_KEY"
```

```bash tab="x-api-key"
curl https://druckling-nine.vercel.app/v1/templates \
  -H "x-api-key: $DRUCKLING_API_KEY"
```

The key decides the workspace and the mode: `dr_test_…` keys work in [test mode](/docs/concepts/test-mode), `dr_live_…` keys in live mode. Some endpoints need a key with full access. See [Authentication](/docs/authentication) for permissions and the errors you get without them.

## Resources and IDs [#resources-and-ids]

Every resource has an `object` field naming its type and an `id` with a prefix you can recognize:

| Resource | `object` | ID prefix |
| --- | --- | --- |
| [Document](/docs/api-reference/documents/get) | `document` | `pdf_` |
| [Batch](/docs/api-reference/batches/get) | `batch` | `bat_` |
| [Share link](/docs/api-reference/share-links/create) | `share_link` | `shl_` |
| [Webhook endpoint](/docs/api-reference/webhooks/get) | `webhook_endpoint` | `whe_` |
| [Embedded editor session](/docs/api-reference/embedded-editor/create) | `embed_session` | `emb_` |
| [Template](/docs/api-reference/templates/get) | `template` | addressed by its `slug` |

## Lists and pagination [#lists-and-pagination]

List endpoints return `{ "object": "list", "data": [...] }`. Documents, batches and a batch's documents are paginated: pass `limit` (1 to 100) and, for the next page, `cursor` set to the previous response's `next_cursor`. `next_cursor` is `null` on the last page. Templates, webhook endpoints and share links come back in one list. The [SDKs](/docs/sdks) iterate through pages for you.

## Status codes [#status-codes]

| Status | Meaning |
| --- | --- |
| `200` | It worked. `POST /v1/documents` answers `200` when it waited for the render. |
| `201` | A webhook endpoint, share link or embedded editor session was created. |
| `202` | Accepted and queued: `POST /v1/documents` with `async: true`, and every batch. |
| `400` | The request doesn't match the API's schema (`data.issues` lists the problems). |
| `401` / `403` | The API key is missing or invalid, or lacks a permission. |
| `404` | The resource doesn't exist in your workspace, or the endpoint doesn't exist. |
| `409` | The request conflicts with the resource's state, e.g. canceling a finished batch. |
| `413` | The request body is too large. |
| `422` | The payload doesn't match the template's schema, a business rule failed, or the render failed. |
| `429` | A quota or rate limit was reached. |
| `504` | The render took too long. |

Every error has the same JSON shape, with Druckling's own code in `data.code` and the offending field in `data.field`. See [Errors](/docs/concepts/errors) for the full list and for which errors are safe to retry, and [Plans and limits](/docs/concepts/plans-and-limits) for quotas and rate limits.

## OpenAPI [#openapi]

The OpenAPI 3.1 document behind this reference is served at [`/v1/openapi.json`](/v1/openapi.json). Use it to generate a client in another language or to import the API into a tool such as Postman or Insomnia. An interactive Scalar reference is also available at [`/v1/docs`](/v1/docs).
