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

# Merge PDFs

> Combine 2 to 20 PDFs into one document with the hosted API.

`POST /v1/merge`

Merges PDFs into one document, in array order. See the [Merge API reference](https://docs.formepdf.com/api-reference/merge.md) for what is and is not carried over from the source files.

Each successful call is one [operation](https://docs.formepdf.com/hosted-api.md#operations-and-plan-limits).

***

## Request body

| Field | Type | Required | Description |
| - | - | - | - |
| `pdfs` | `string[]` | Yes | Base64-encoded PDFs. At least 2, at most 20. |

The whole JSON body can be up to 20 MB, base64 included.

```bash curl theme={null}
curl -X POST https://api.formepdf.com/v1/merge \
  -H "Authorization: Bearer forme_sk_abc123..." \
  -H "Content-Type: application/json" \
  -d "{
    \"pdfs\": [
      \"$(base64 -w0 invoice.pdf)\",
      \"$(base64 -w0 terms.pdf)\"
    ]
  }" \
  --output combined.pdf
```

```javascript Node.js theme={null}
const res = await fetch("https://api.formepdf.com/v1/merge", {
  method: "POST",
  headers: {
    Authorization: "Bearer forme_sk_abc123...",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    pdfs: ["invoice.pdf", "terms.pdf"].map((f) => fs.readFileSync(f).toString("base64")),
  }),
});

fs.writeFileSync("combined.pdf", Buffer.from(await res.arrayBuffer()));
```

***

## Response

`200 OK`, `Content-Type: application/pdf`. The body is the merged PDF. It is not saved to [Documents](https://docs.formepdf.com/hosted-api/documents.md).

Fewer than 2 or more than 20 PDFs returns `400`.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.