D
Druckling
Docs

Errors

The shape of Druckling API errors, every error code and its HTTP status, and how to retry without rendering a document twice.

Druckling answers every request with a conventional HTTP status code: 2xx when it worked, 4xx when something about the request needs to change, and 5xx when something went wrong on Druckling's side. Errors come with a JSON body that tells you what happened and, for most errors, which field caused it.

Error format

422 Unprocessable Content
{
  "defined": false,
  "code": "UNPROCESSABLE_CONTENT",
  "status": 422,
  "message": "Required field customer.address was missing from the request payload",
  "data": {
    "code": "schema_validation_failed",
    "field": "customer.address",
    "documentId": "pdf_6Jd2pRw9tL4xQ8sM",
    "errors": [
      { "field": "customer.address", "message": "missing required field customer.address" },
      { "field": "invoice.due_date", "message": "invoice.due_date must be a date like 2026-11-22" }
    ]
  }
}

Prop

Type

Depending on the error, data holds more fields, such as documentId, errors, retryAfter or diagnostics. They're described with each code below.

A few responses don't have data.code: request validation errors (400), unexpected server errors (500) and requests to an unknown endpoint (404). Fall back to the top-level code for those, which is what the SDKs do.

Request validation errors

Before a request reaches Druckling's own checks, its shape is validated against the API's schema: required fields, types, allowed values and ranges. A request that doesn't match fails with 400 BAD_REQUEST, and data.issues lists every problem:

curl https://druckling-nine.vercel.app/v1/documents \
  -H "Authorization: Bearer $DRUCKLING_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "data": { "invoice": { "number": "INV-2041" } }, "async": "yes" }'
400 Bad Request
{
  "defined": false,
  "code": "BAD_REQUEST",
  "status": 400,
  "message": "Input validation failed",
  "data": {
    "issues": [
      {
        "expected": "string",
        "code": "invalid_type",
        "path": ["template"],
        "message": "Invalid input: expected string, received undefined"
      },
      {
        "expected": "boolean",
        "code": "invalid_type",
        "path": ["async"],
        "message": "Invalid input: expected boolean, received string"
      }
    ]
  }
}

Each issue's path is an array of keys and array indexes. A body that isn't valid JSON gets 400 with the message "Malformed request…" and no data. Fields the API doesn't know are ignored, not rejected.

The API key is checked first, so a request with a missing or invalid key gets 401 even if its body is also invalid.

Error codes

data.codeStatuscodeWhen it happens
unauthorized401UNAUTHORIZEDThe API key is missing ("Missing API key…"), or it's invalid or revoked ("Invalid or revoked API key").
forbidden403FORBIDDENThe key lacks a permission, for example a Render only key reading templates, managing webhooks or creating editor sessions.
not_found404NOT_FOUNDNo such document, batch, share link, webhook endpoint or template. Also a template without a published version (field: "template") and an unknown version (field: "version").
conflict409CONFLICTA count limit is reached: 20 active share links per document, or 20 webhook endpoints per workspace.
invalid_state409CONFLICTThe object can't do that right now: sharing a document that isn't rendered, canceling a batch that already finished, or creating an editor session before any origin is allowed in Settings › Embed.
stale_revision409CONFLICTOnly in the dashboard and editors: someone else saved the template first. The REST API doesn't return it.
schema_validation_failed422UNPROCESSABLE_CONTENTdata doesn't match the template's JSON Schema: a required field is missing, or a value has the wrong type or format.
validation_failed422UNPROCESSABLE_CONTENTThe request is well-formed but breaks a rule the schema can't express: a format or image option the template doesn't support, a PNG image.page past the end of the document, a language the template doesn't have, an e-invoice business rule, or data nested deeper than 32 levels.
payload_too_large413PAYLOAD_TOO_LARGEdata is larger than 1,000,000 bytes, an array in it has more than 10,000 items, or a batch's items exceed 4 MB.
quota_exceeded429QUOTA_EXCEEDEDYour plan's daily or monthly live document quota is used up.
rate_limited429TOO_MANY_REQUESTSThe API key made too many requests, too many editor sessions were created at once, or the render engine is busy.
render_failed422UNPROCESSABLE_CONTENTThe template couldn't be rendered: a Typst error, more pages than your plan allows, or an unexpected failure while rendering or storing the file.
render_timeout504GATEWAY_TIMEOUTTypesetting took longer than 10 seconds and was stopped.

And the responses without data.code:

StatuscodeWhen it happens
400BAD_REQUESTThe request doesn't match the API's schema, or the body isn't valid JSON. See request validation errors.
404NOT_FOUNDThe path doesn't exist. The body is just { "code": "NOT_FOUND", "message": "Unknown endpoint" }.
500INTERNAL_SERVER_ERRORSomething unexpected went wrong on Druckling's side. The message is "Internal server error".

Limits behind these codes are listed in Plans and limits.

Validation errors

Druckling validates a render request in two steps, and the code tells you which one failed:

  • schema_validation_failed: data doesn't match the template's JSON Schema. data.field is the first problem, with missing fields first, and data.errors lists every problem as { field, message }.
  • validation_failed: the payload has the right shape but breaks a rule, or the request asks for something the template can't do. For e-invoice templates, data.errors lists the broken business rules, each with a rule such as BR-CO-25, and the rule's ID also appears in the message. See E-invoicing.

Field paths are dotted, and array indexes are numbers: line_items.2.qty is the qty of the third line item.

When data fails either check, Druckling still creates a document, in status failed, and data.documentId holds its ID. That's how the attempt shows up in Documents in the dashboard, and why it triggers a document.failed webhook. It doesn't count toward your quota. Errors about the request itself, such as an unsupported format or an unknown language, are rejected before a document is created.

Batch validation errors

POST /v1/batches validates every item before rendering anything. If any item is invalid, nothing is rendered, no documents are created, and the answer is 422. data.field points into the first invalid item, data.invalidItems counts the invalid items, and data.errors lists the first problem of each of the first 20 invalid items, with field relative to that item's data:

422 Unprocessable Content
{
  "defined": false,
  "code": "UNPROCESSABLE_CONTENT",
  "status": 422,
  "message": "Item 3: Required field customer.address was missing from the request payload (2 of 50 items are invalid)",
  "data": {
    "code": "schema_validation_failed",
    "field": "items.3.data.customer.address",
    "invalidItems": 2,
    "errors": [
      { "index": 3, "field": "customer.address", "message": "Required field customer.address was missing from the request payload" },
      { "index": 17, "field": "invoice.due_date", "message": "Required field invoice.due_date was missing from the request payload" }
    ]
  }
}

See Batches for the whole flow.

Render errors

render_failed (422) means the template couldn't be turned into a file with this payload:

  • A Typst error. data.diagnostics lists the engine's messages, each with a severity, a message, and the template block it came from when Druckling can tell. Open the template in the editor with the same data to see the problem.
  • Too many pages. "The document has 64 pages; the limit is 50", with the count in data.pages.
  • An unexpected failure, such as "Rendering failed unexpectedly". These can be temporary.

render_timeout (504) means typesetting took longer than 10 seconds and was stopped.

In both cases the document is recorded as failed with the same error.code, and it doesn't count toward your quota. With async: true you don't get these errors on the request: the document ends up failed instead, and document.failed tells you. See Documents.

Retrying

Whether a retry can help depends on the error:

ErrorRetry?
429 rate_limitedYes, after a pause. Wait for the Retry-After header (also in data.retryAfter). The per-key limit counts 120 requests a minute. See rate limits.
429 quota_exceededNo. Wait for the quota to reset, upgrade, or use a test key while developing.
500 and other 5xxYes for GET and DELETE, with exponential backoff. For POST, read idempotency first.
504 render_timeoutAt most once. If it times out again, make the document lighter, for example with fewer table rows or images.
422 render_failedNot until you fix the template or the payload, unless it's an unexpected failure without data.diagnostics.
400, 401, 403, 404, 409, 413, other 422No. Fix the request first.
No response (network error, client timeout)Yes for GET and DELETE. For POST, the server may have done the work: read idempotency.

Each POST /v1/documents that Druckling accepts creates a new document, and attempts that failed validation or rendering stay in your document list as failed documents.

Idempotency

The API doesn't support idempotency keys. An Idempotency-Key header is ignored, and every POST /v1/documents that passes validation renders a new document, which counts toward your quota in live mode.

Duplicates happen when a request reaches Druckling but the response never reaches you: the connection drops, or your client times out during a synchronous render. The document may have rendered anyway. To keep this from creating duplicates:

  • Name documents uniquely. Set filename to something unique, such as the invoice number. After a network error or a 5xx, list recent documents for the template and look for that file name before you render again.
  • Store the ID right away. Once you have a document's ID, everything else (retrieving, waiting, downloading) is a GET that is safe to retry.
  • Shorten the window. With async: true the request returns as soon as the payload is validated, so a dropped connection during a slow render can't leave you without the document ID.
render-once.ts
import Druckling, { APIConnectionError, ServerError } from "@druckling/sdk";

const druckling = new Druckling();

export async function renderInvoice(number: string, data: Record<string, unknown>) {
  const filename = `${number}.pdf`;
  try {
    return await druckling.documents.create({ template: "invoice-standard", filename, data });
  } catch (error) {
    if (!(error instanceof APIConnectionError || error instanceof ServerError)) throw error;
    const recent = await druckling.documents.list({ template: "invoice-standard", limit: 20 });
    const existing = recent.data.find((doc) => doc.filename === filename && doc.status !== "failed");
    if (existing) return druckling.documents.wait(existing.id);
    return druckling.documents.create({ template: "invoice-standard", filename, data });
  }
}

The same applies to POST /v1/batches: sending it twice starts two batches.

What the SDKs retry

The SDKs retry up to 2 times by default. They resend a POST only when Druckling rejected it without rendering anything:

  • 429 rate_limited is retried for every method, including POST /v1/documents. A rate-limited request rendered nothing.
  • 429 quota_exceeded is never retried.
  • 408, 5xx, timeouts and connection errors are retried for GET and DELETE only.

See SDKs for backoff and configuration.

Errors in the SDKs

Each SDK raises one error class per kind of failure, all under one base class, and they carry the same information as the JSON body:

What you getTypeScript and PythonPHP
Error codeerror.code$e->errorCode
HTTP statuserror.status$e->status
Offending fielderror.field$e->field
All field errorserror.errors$e->errors
Failed document IDerror.documentId (TS), error.document_id (Python)$e->documentId
Request IDerror.requestId (TS), error.request_id (Python)$e->requestId

errors combines data.errors and the data.issues of request validation errors, each as a field and a message. Classes by error:

ErrorTypeScript and PythonPHP
400 BAD_REQUEST, schema_validation_failed, validation_failedValidationErrorValidationException
unauthorizedAuthenticationErrorAuthenticationException
forbiddenPermissionDeniedErrorPermissionDeniedException
not_foundNotFoundErrorNotFoundException
conflict, invalid_stateConflictErrorConflictException
render_failed, render_timeoutRenderErrorRenderException
rate_limitedRateLimitErrorRateLimitException
quota_exceededQuotaExceededError, a RateLimitErrorQuotaExceededException, a RateLimitException
5xxServerErrorServerException
payload_too_largeAPIErrorApiException
No responseAPIConnectionError, or APITimeoutError on timeoutConnectionException, or TimeoutException on timeout
import Druckling, { QuotaExceededError, ValidationError } from "@druckling/sdk";

const druckling = new Druckling();

try {
  await druckling.documents.create({ template: "invoice-standard", data });
} catch (error) {
  if (error instanceof ValidationError) {
    for (const issue of error.errors) console.error(`${issue.field}: ${issue.message}`);
  } else if (error instanceof QuotaExceededError) {
    console.error("Quota used up:", error.message);
  } else {
    throw error;
  }
}

The SDK pages cover each language's error classes in detail: TypeScript, Python, PHP.

Debugging

  • Every request that gets past the API key check shows up in Developers › Logs, with its status and duration. Requests rejected for a missing or invalid key don't; requests rejected by the per-key rate limit do, with status 429.
  • Failed renders appear in Documents with their error, the offending field and the request body as received.
  • Each response has an x-vercel-id header that identifies the request. The SDKs expose it as the error's request ID. Include it when you contact support.

On this page