> ## Documentation Index
> Fetch the complete documentation index at: https://pdfbase.dev/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Quickstart

> Generate your first PDF in under 2 minutes.

## 1. Get your API key

Sign up at [app.pdfbase.dev](https://app.pdfbase.dev/signup) and copy your test API key from the dashboard. Test keys are prefixed with `pk_test_` and generate watermarked PDFs at no cost.

## 2. Generate a PDF

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST https://api.pdfbase.dev/v1/pdfs \
    -H "Authorization: Bearer pk_test_YOUR_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "html": "<h1>Hello from PDFBase</h1><p>Your first PDF.</p>",
      "format": "a4",
      "output": "url"
    }'
  ```

  ```typescript TypeScript theme={null}
  import PDFBase from '@pdfbase/sdk'

  const pdfbase = new PDFBase({ apiKey: 'pk_test_YOUR_KEY' })

  const pdf = await pdfbase.pdfs.create({
    html: '<h1>Hello from PDFBase</h1><p>Your first PDF.</p>',
    format: 'a4',
    output: 'url',
  })

  console.log(pdf.url) // https://files.pdfbase.dev/pdf_x7Kf9m.pdf
  ```

  ```python Python theme={null}
  from pdfbase import PDFBase

  client = PDFBase(api_key="pk_test_YOUR_KEY")

  pdf = client.pdfs.create(
      html="<h1>Hello from PDFBase</h1><p>Your first PDF.</p>",
      format="a4",
      output="url",
  )

  print(pdf.url)  # https://files.pdfbase.dev/pdf_x7Kf9m.pdf
  ```

  ```bash CLI theme={null}
  pdfbase create --html "<h1>Hello from PDFBase</h1>" -o hello.pdf
  ```
</CodeGroup>

### Response

```json theme={null}
{
  "id": "pdf_x7Kf9m",
  "object": "pdf",
  "status": "completed",
  "url": "https://files.pdfbase.dev/pdf_x7Kf9m.pdf?token=sig_abc123",
  "pages": 1,
  "bytes": 24310,
  "format": "a4",
  "created_at": "2026-05-19T10:30:00Z",
  "expires_at": "2026-05-20T10:30:00Z"
}
```

<Note>
  File URLs are signed and expire after 24 hours by default. Use the `GET /v1/pdfs/:id` endpoint to generate a fresh URL.
</Note>

## 3. Use a template

Templates let you separate layout from data. Define your HTML once, then render it with different data on every call.

<CodeGroup>
  ```bash cURL theme={null}
  # Create a template
  curl -X POST https://api.pdfbase.dev/v1/templates \
    -H "Authorization: Bearer pk_test_YOUR_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "name": "invoice",
      "html": "<h1>Invoice #{{number}}</h1><p>{{customer}}</p><p>Total: {{total}}</p>",
      "schema": {
        "number": "string",
        "customer": "string",
        "total": "string"
      }
    }'

  # Render it with data
  curl -X POST https://api.pdfbase.dev/v1/templates/tpl_abc123/render \
    -H "Authorization: Bearer pk_test_YOUR_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "data": {
        "number": "INV-001",
        "customer": "Acme Corp",
        "total": "$1,250.00"
      },
      "output": "url"
    }'
  ```

  ```typescript TypeScript theme={null}
  const template = await pdfbase.templates.create({
    name: 'invoice',
    html: '<h1>Invoice #{{number}}</h1><p>{{customer}}</p><p>Total: {{total}}</p>',
    schema: {
      number: 'string',
      customer: 'string',
      total: 'string',
    },
  })

  const pdf = await pdfbase.templates.render(template.id, {
    data: {
      number: 'INV-001',
      customer: 'Acme Corp',
      total: '$1,250.00',
    },
    output: 'url',
  })
  ```
</CodeGroup>

## 4. Enable debug mode

When something looks wrong, pass `debug: true` to get a screenshot of the rendered page, console output, and a list of any resources that failed to load.

```bash theme={null}
curl -X POST https://api.pdfbase.dev/v1/pdfs \
  -H "Authorization: Bearer pk_test_YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "html": "<link href=\"https://fonts.example.com/broken.css\" rel=\"stylesheet\"><h1>Debug me</h1>",
    "debug": true,
    "output": "url"
  }'
```

```json theme={null}
{
  "id": "pdf_debug1",
  "object": "pdf",
  "status": "completed",
  "url": "https://files.pdfbase.dev/pdf_debug1.pdf?token=sig_xyz",
  "pages": 1,
  "bytes": 18200,
  "debug": {
    "screenshot_url": "https://files.pdfbase.dev/debug/pdf_debug1.png",
    "console": [
      { "level": "error", "message": "Failed to load resource: net::ERR_NAME_NOT_RESOLVED" }
    ],
    "failed_resources": [
      { "url": "https://fonts.example.com/broken.css", "status": null, "error": "net::ERR_NAME_NOT_RESOLVED" }
    ]
  },
  "created_at": "2026-05-19T10:31:00Z",
  "expires_at": "2026-05-20T10:31:00Z"
}
```

## Next steps

<CardGroup cols={2}>
  <Card title="Authentication" icon="key" href="/docs/authentication">
    API key management, test vs. live keys
  </Card>

  <Card title="Templates guide" icon="file-code" href="/docs/guides/templates">
    Build reusable templates with Handlebars + CSS
  </Card>

  <Card title="Batch processing" icon="layer-group" href="/docs/guides/batch-processing">
    Generate hundreds of PDFs in a single API call
  </Card>

  <Card title="Webhooks" icon="bell" href="/docs/webhooks">
    Get notified when async jobs complete
  </Card>
</CardGroup>
