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

# Generate PDF

> Generates a PDF document from a JSON payload and a Typst template string.

<Warning>
  **Zero Data Retention Policy**: PDFDyno operates purely in-memory. The JSON payload, the Typst template, and the generated PDF are **instantly and permanently deleted** from our servers the moment the HTTP response is sent. We do not store any of your data.
</Warning>

## Authentication

This endpoint requires a Bearer token. Pass your API key in the `Authorization` header.

```http theme={null}
Authorization: Bearer sk_live_YOUR_API_KEY
```

## System Limits

* **Max Payload Size:** `10 MB`
* **Max Timeout:** `10 seconds` (Documents must compile within this time)
* **Rate Limit:** `100 requests / minute` (on Starter plan)
* **Typst Version:** `0.11.0`

## Request Headers

<ParamField header="Content-Type" type="string" required>
  Must be `application/json`.
</ParamField>

## Request Body

<ParamField body="data" type="object" required>
  The JSON data object containing the dynamic variables you want to inject into your PDF. The backend automatically injects this data into your template as a `#data` variable.
</ParamField>

<ParamField body="template" type="string" required>
  The raw Typst markup template string. Use `#data.field` to access variables from your `data`.
</ParamField>

### Example Request

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST https://api.pdfdyno.com/v1/pdf/generate \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "template": "= #data.title\n\nThis is a report.",
      "data": {
        "title": "Monthly Report"
      }
    }' \
    --output report.pdf
  ```

  ```javascript Node.js theme={null}
  const response = await fetch('https://api.pdfdyno.com/v1/pdf/generate', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer YOUR_API_KEY',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      template: "= #data.title\n\nThis is a report.",
      data: {
        title: "Monthly Report"
      }
    })
  });

  const buffer = Buffer.from(await response.arrayBuffer());
  ```

  ```python Python theme={null}
  import requests

  response = requests.post(
      "https://api.pdfdyno.com/v1/pdf/generate",
      headers={"Authorization": "Bearer YOUR_API_KEY"},
      json={
          "template": "= #data.title\n\nThis is a report.",
          "data": {"title": "Monthly Report"},
      }
  )

  with open("report.pdf", "wb") as f:
      f.write(response.content)
  ```
</CodeGroup>

## Response Headers

PDFDyno returns the following headers on every request to help you handle rate limits gracefully.

<ResponseField header="X-RateLimit-Remaining" type="integer">
  The number of requests remaining in the current one-minute window.
</ResponseField>

<ResponseField header="X-RateLimit-Reset" type="integer">
  Returned on every request (and particularly with `429 Too Many Requests`). A UNIX timestamp indicating when the rate limit window resets.
</ResponseField>

## Response Body

Returns the raw PDF binary.

<ResponseExample>
  ```json 400 Bad Request theme={null}
  {
    "error": "Invalid Typst syntax on line 2"
  }
  ```

  ```json 401 Unauthorized theme={null}
  {
    "error": "Missing or invalid API Key"
  }
  ```

  ```json 413 Payload Too Large theme={null}
  {
    "error": "Payload exceeds 10MB limit"
  }
  ```

  ```json 429 Too Many Requests theme={null}
  {
    "error": "Rate limit exceeded"
  }
  ```

  ```json 500 Internal Server Error theme={null}
  {
    "error": "An unexpected error occurred during document compilation."
  }
  ```

  ```json 503 Service Unavailable theme={null}
  {
    "error": "Service temporarily unavailable. Please try again later."
  }
  ```
</ResponseExample>
