# Quick start

Generate a PDF with one REST request. If you want to use an AI client, start with [MCP setup](https://pdf-mcp.io/docs/mcp-server).

## 1. Create an account and API key

1. Open [app.pdf-mcp.io](https://app.pdf-mcp.io), enter your email, and follow the magic link to sign in.
2. Select the workspace you want the integration to use.
3. Open **API Keys**, select **Create New API Key**, and give the key a name.
4. Copy the full key immediately; it is shown only once.

Store the key as an environment variable named `PDF_MCP_API_KEY` in your local shell or secret manager. Keys start with `pdfmcp_`. Keep them out of source control and browser code.

## 2. Generate a PDF

```bash
curl --fail-with-body https://api.pdf-mcp.io/htmlToPdf \
  -H "Authorization: Bearer $PDF_MCP_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "html": "<h1>Hello, PDF!</h1><p>This is my first document.</p>",
    "storage": { "mode": "memory" }
  }' \
  --output my-first.pdf
```

On success, open `my-first.pdf` in your PDF viewer. The explicit `memory` storage mode returns PDF bytes directly and creates no stored document, regardless of the workspace's default storage setting.

If curl reports an error, the output file may contain the error response instead of a PDF. Use the troubleshooting table below.

## Python

With the `requests` package installed and `PDF_MCP_API_KEY` in your environment:

```python
import os
from pathlib import Path

import requests

response = requests.post(
    "https://api.pdf-mcp.io/htmlToPdf",
    headers={"Authorization": f"Bearer {os.environ['PDF_MCP_API_KEY']}"},
    json={
        "html": "<h1>Hello from Python!</h1>",
        "storage": {"mode": "memory"},
    },
    timeout=60,
)
response.raise_for_status()
Path("output.pdf").write_bytes(response.content)
```

## Node.js

Save this example as `generate.mjs`, then run `node generate.mjs` with `PDF_MCP_API_KEY` available in the environment:

```javascript
import { writeFile } from 'node:fs/promises';

const apiKey = process.env.PDF_MCP_API_KEY;
if (!apiKey) throw new Error('Set PDF_MCP_API_KEY before running this example.');

const response = await fetch('https://api.pdf-mcp.io/htmlToPdf', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${apiKey}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    html: '<h1>Hello from Node.js!</h1>',
    storage: { mode: 'memory' },
  }),
});

if (!response.ok) {
  throw new Error(`PDF request failed (${response.status}): ${await response.text()}`);
}

await writeFile('output.pdf', Buffer.from(await response.arrayBuffer()));
```

## Troubleshooting

| Result | What to check |
| --- | --- |
| `401 Unauthorized` | Send the `Authorization: Bearer …` header with your key |
| `402 Payment Required` | Check the workspace balance and your member credit limit |
| `403 Forbidden` | Check that the key is active and its creator still has the required workspace access |
| `422 Unprocessable Entity` | Check the request body against the [endpoint reference](https://pdf-mcp.io/docs/api-html-to-pdf) |
| Missing images or styles | Use accessible absolute URLs, or set `base_url` for relative resources |

## Next steps

- [HTML to PDF](https://pdf-mcp.io/docs/api-html-to-pdf): add CSS, page settings, and a filename.
- [Storage modes](https://pdf-mcp.io/docs/storage-modes): keep documents in private managed storage or your own bucket.
- [API reference](https://pdf-mcp.io/docs/api-reference): extract text, merge PDFs, and use other endpoints.
- [Authentication](https://pdf-mcp.io/docs/authentication): revoke keys and configure OAuth.
