# Quickstart (/docs/quickstart)

> Create an account and a test API key, then render your first PDF from the invoice-standard template with cURL or an SDK.

This guide takes you from a new account to a rendered PDF. You'll use a test API key, so nothing you render counts toward your plan's quota.

<Steps>

<Step>

### Create an account [#create-an-account]

Sign up at [druckling-nine.vercel.app/sign-up](https://druckling-nine.vercel.app/sign-up) with your name, work email and a password of at least 8 characters. Then name your workspace. A workspace holds your templates, documents, API keys and team.

New workspaces start on the Free plan with six starter templates: Invoice (`invoice-standard`), Course certificate, Quarterly report, Event ticket, Rental agreement and Packing slip. `invoice-standard` is already published, so you can render it right away. The other starters are drafts.

</Step>

<Step>

### Create a test API key [#create-a-test-api-key]

In the dashboard, go to **Developers › API keys** and click **Create API key**:

1. Name the key after what uses it, for example `quickstart`.
2. Keep **Test** as the mode and **Render only** as the permission.
3. Click **Create key** and copy the key. It's shown only once.

Store it in an environment variable. The SDKs read `DRUCKLING_API_KEY` by default:

```bash
export DRUCKLING_API_KEY="dr_test_…"
```

Test keys render real documents for free and keep their data apart from live data; see [Test mode](/docs/concepts/test-mode). Only owners and admins can create keys, and you're the owner of the workspace you created. See [Authentication](/docs/authentication) for permissions, rotation and revocation.

</Step>

<Step>

### Check that the template is published [#check-that-the-template-is-published]

The API only renders published versions. Publishing freezes the template's draft into an immutable version (v1, v2, …), so editing a template never changes what your integration produces until you publish again.

`invoice-standard` is published as v1, so there's nothing to do for this guide. To render another template, open it under **Templates**, open the editor and click **Publish**, then **Publish v1**. Publishing checks that the template has no errors, that its sample data matches its variables and that it renders.

<Callout type="warn" title="Unpublished templates return 404">

Rendering a template that was never published fails with `404 Not Found`:

```json
{
  "defined": false,
  "code": "NOT_FOUND",
  "status": 404,
  "message": "Template quarterly-report has no published version yet; publish it first",
  "data": { "code": "not_found", "field": "template" }
}
```

</Callout>

</Step>

<Step>

### Render your first PDF [#render-your-first-pdf]

Send the template slug and your data to [`POST /v1/documents`](/docs/api-reference/documents/create). The request waits while the PDF renders and returns the finished document.

To use an SDK, install it first:

<Callout type="info" title="Registry packages are coming">

The SDKs aren't on npm, PyPI or Packagist yet. Until they are, install them from the Druckling source repository.

</Callout>

```bash tab="TypeScript"
git clone https://github.com/vulpery/druckling.git
cd druckling/src/integrations/sdk-typescript
npm install && npm run build && npm pack

# then, in your project
npm install /path/to/druckling-sdk-0.1.0.tgz
```

```bash tab="Python"
pip install "git+https://github.com/vulpery/druckling.git#subdirectory=src/integrations/sdk-python"
```

```bash tab="PHP"
git clone https://github.com/vulpery/druckling.git

# then, in your project
composer config repositories.druckling path /path/to/druckling/src/integrations/sdk-php
composer require druckling/druckling-php:@dev
```

Then render the invoice:

```bash tab="cURL"
curl https://druckling-nine.vercel.app/v1/documents \
  -H "Authorization: Bearer $DRUCKLING_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "template": "invoice-standard",
    "filename": "INV-2041.pdf",
    "data": {
      "invoice": { "number": "INV-2041", "due_date": "2026-11-22" },
      "customer": { "name": "Northwind Ltd.", "address": "12 Pier St, Leeds" },
      "line_items": [
        { "description": "Brand identity, phase 2", "qty": 1, "rate": 4800, "amount": 4800 },
        { "description": "Design system audit", "qty": 12, "rate": 180, "amount": 2160 }
      ],
      "totals": { "subtotal": 6960, "tax": 556.8, "amount": 7516.8 },
      "payment": { "url": "https://pay.example.com/INV-2041" }
    }
  }'
```

```ts tab="TypeScript"
import { writeFile } from "node:fs/promises";
import Druckling from "@druckling/sdk";

const druckling = new Druckling(); // reads DRUCKLING_API_KEY

const document = await druckling.documents.create({
  template: "invoice-standard",
  filename: "INV-2041.pdf",
  data: {
    invoice: { number: "INV-2041", due_date: "2026-11-22" },
    customer: { name: "Northwind Ltd.", address: "12 Pier St, Leeds" },
    line_items: [
      { description: "Brand identity, phase 2", qty: 1, rate: 4800, amount: 4800 },
      { description: "Design system audit", qty: 12, rate: 180, amount: 2160 },
    ],
    totals: { subtotal: 6960, tax: 556.8, amount: 7516.8 },
    payment: { url: "https://pay.example.com/INV-2041" },
  },
});

console.log(document.status, document.url);
await writeFile("INV-2041.pdf", await druckling.documents.download(document));
```

```python tab="Python"
from druckling import Druckling

client = Druckling()  # reads DRUCKLING_API_KEY

document = client.documents.create(
    template="invoice-standard",
    filename="INV-2041.pdf",
    data={
        "invoice": {"number": "INV-2041", "due_date": "2026-11-22"},
        "customer": {"name": "Northwind Ltd.", "address": "12 Pier St, Leeds"},
        "line_items": [
            {"description": "Brand identity, phase 2", "qty": 1, "rate": 4800, "amount": 4800},
            {"description": "Design system audit", "qty": 12, "rate": 180, "amount": 2160},
        ],
        "totals": {"subtotal": 6960, "tax": 556.8, "amount": 7516.8},
        "payment": {"url": "https://pay.example.com/INV-2041"},
    },
)

print(document.status, document.url)
client.documents.download_to(document, "INV-2041.pdf")
```

```php tab="PHP"
<?php

require __DIR__ . '/vendor/autoload.php';

use Druckling\Druckling;

$druckling = new Druckling(); // reads DRUCKLING_API_KEY

$document = $druckling->documents->create(
    template: 'invoice-standard',
    data: [
        'invoice' => ['number' => 'INV-2041', 'due_date' => '2026-11-22'],
        'customer' => ['name' => 'Northwind Ltd.', 'address' => '12 Pier St, Leeds'],
        'line_items' => [
            ['description' => 'Brand identity, phase 2', 'qty' => 1, 'rate' => 4800, 'amount' => 4800],
            ['description' => 'Design system audit', 'qty' => 12, 'rate' => 180, 'amount' => 2160],
        ],
        'totals' => ['subtotal' => 6960, 'tax' => 556.8, 'amount' => 7516.8],
        'payment' => ['url' => 'https://pay.example.com/INV-2041'],
    ],
    filename: 'INV-2041.pdf',
);

echo $document->status, ' ', $document->url, PHP_EOL;
$druckling->documents->downloadTo($document, __DIR__ . '/INV-2041.pdf');
```

The template prints the values you send; it doesn't calculate totals. Each template's **API** tab in the dashboard shows this request with the template's own sample data.

</Step>

<Step>

### Handle the response [#handle-the-response]

A successful render returns `200 OK` with the [document](/docs/api-reference/documents/get):

```json
{
  "id": "pdf_8Qw2kLm3nP0aB1cD",
  "object": "document",
  "status": "rendered",
  "template": "invoice-standard",
  "version": 1,
  "filename": "INV-2041.pdf",
  "format": "pdf",
  "content_type": "application/pdf",
  "image": null,
  "pages": 1,
  "size_bytes": 41873,
  "url": "https://…",
  "expires_at": "2026-11-26T09:41:07.312Z",
  "error": null,
  "einvoice": null,
  "batch": null,
  "language": "en",
  "test_mode": true,
  "created_at": "2026-10-27T09:41:06.208Z"
}
```

- `status` is `rendered`: the file is ready.
- `url` is a signed link to the PDF. It needs no API key and works for up to 7 days. Download the file right away, or retrieve the document again with [`GET /v1/documents/{id}`](/docs/api-reference/documents/get) for a fresh link.
- `expires_at` is when Druckling deletes the file: 30 days after rendering. After that the document's status becomes `expired` and it has no `url`.
- `version` is the template version that was rendered, and `test_mode` tells you which mode the key used.

With cURL, download the file from `url`:

```bash
curl -o INV-2041.pdf "https://…"
```

For large documents, send `"async": true`. The response then comes back right away with `202 Accepted`, `status: "queued"` and no `url` yet. Poll the document or wait for a [webhook](/docs/guides/webhooks); see [Documents](/docs/concepts/documents).

#### When the data doesn't match [#when-the-data-doesnt-match]

Druckling validates `data` against the template's JSON Schema before rendering. If you leave out `invoice.number`, the request fails with `422 Unprocessable Content`:

```json
{
  "defined": false,
  "code": "UNPROCESSABLE_CONTENT",
  "status": 422,
  "message": "Required field invoice.number was missing from the request payload",
  "data": {
    "code": "schema_validation_failed",
    "field": "invoice.number",
    "documentId": "pdf_3Hk9QmZ1xT7pLw2V",
    "errors": [
      { "field": "invoice.number", "message": "missing required field invoice.number" }
    ]
  }
}
```

- `data.code` is the machine-readable error code. Schema mismatches are `schema_validation_failed`; other invalid input, such as a language the template doesn't have, is `validation_failed`.
- `data.field` is the dotted path of the first offending field, for example `line_items.1.qty`. `data.errors` lists every problem found, missing fields first.
- The failed attempt is recorded as a `failed` document (`data.documentId`), so you can inspect it under **Documents** in the dashboard. Failed renders don't count toward your quota.

The SDKs raise this as a validation error with the same details. Here `payload` stands for the data you send:

```ts tab="TypeScript"
import Druckling, { ValidationError } from "@druckling/sdk";

const druckling = new Druckling();

try {
  await druckling.documents.create({ template: "invoice-standard", data: payload });
} catch (error) {
  if (!(error instanceof ValidationError)) throw error;
  for (const problem of error.errors) console.error(`${problem.field}: ${problem.message}`);
}
```

```python tab="Python"
from druckling import Druckling, ValidationError

client = Druckling()

try:
    client.documents.create(template="invoice-standard", data=payload)
except ValidationError as error:
    for problem in error.errors:
        print(f"{problem.field}: {problem.message}")
```

```php tab="PHP"
use Druckling\Exception\ValidationException;
use Druckling\Druckling;

$druckling = new Druckling();

try {
    $druckling->documents->create(template: 'invoice-standard', data: $payload);
} catch (ValidationException $e) {
    foreach ($e->errors as $problem) {
        echo "{$problem->field}: {$problem->message}", PHP_EOL;
    }
}
```

See [Errors](/docs/concepts/errors) for every error code.

</Step>

</Steps>

## Next steps [#next-steps]

<Cards>
  <Card title="Variables and schemas" href="/docs/concepts/variables">
    Learn how a template's variables become the JSON Schema your data must match.
  </Card>
  <Card title="Documents" href="/docs/concepts/documents">
    Formats, async rendering, polling, retention and signed links.
  </Card>
  <Card title="Webhooks" href="/docs/guides/webhooks">
    Get notified when documents render or fail instead of polling.
  </Card>
  <Card title="Going live" href="/docs/concepts/test-mode">
    What changes when you switch from a test key to a live key.
  </Card>
  <Card title="SDKs" href="/docs/sdks">
    Retries, pagination, downloads and webhook verification in TypeScript, Python and PHP.
  </Card>
  <Card title="API reference" href="/docs/api-reference">
    Every endpoint and field.
  </Card>
</Cards>
