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

# Capture screenshots

> Capture a public web page as a JPEG with your PagePith API key.

Capture a public web page as a 1280 × 800 viewport JPEG. Use the same API key and credit balance as the other PagePith endpoints.

## Capture a page

```bash theme={null}
curl --fail-with-body https://api.pagepith.com/v1/api/screenshot \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"url":"https://example.com"}' \
  --output screenshot.jpg
```

A successful response contains the image bytes with `Content-Type: image/jpeg`. The `X-Final-Url` response header identifies the URL after redirects.

<Note>
  This endpoint returns a JPEG, not JSON. Save the response as an image or read it as a binary buffer.
</Note>

## Use JavaScript

```javascript theme={null}
import { writeFile } from "node:fs/promises";

const response = await fetch("https://api.pagepith.com/v1/api/screenshot", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.PAGEPITH_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({ url: "https://example.com" }),
});

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

await writeFile("screenshot.jpg", Buffer.from(await response.arrayBuffer()));
```

## Credits and limits

Each successful capture costs **5 credits**. Failed captures are not charged. Starter and free accounts need at least 5 available credits before a capture starts. Pro and Business plans can use their configured metered overage.

The endpoint captures the visible viewport at 1280 × 800 pixels. It does not currently support full-page capture, custom viewport sizes, or other image formats. Only public HTTP and HTTPS URLs are accepted.

## Errors

| Status | Meaning |
| - | - |
| 400 | The URL is invalid or points to a private network. |
| 401 | The API key is missing or invalid. |
| 402 | There are not enough credits to capture the page. |
| 422 | The target page returned an error or no screenshot was available. |
| 502 | The browser could not capture the page. |

Error responses contain JSON. See the [screenshot API reference](/api-reference/screenshots/capture) for the request and response details.


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