# Website screenshot API

> PNG or JPEG of any URL. Fast where it can be, stealthy where it has to be.

- Endpoint: `POST https://scrapenest.dev/v1/scrape/screenshot`
- Price: 15 / 25 / 35 credits
- Category: Utilities
- Reference: https://scrapenest.dev/docs#ep-screenshot
- Web page: https://scrapenest.dev/catalog/screenshot
- Updated: 2026-11-04

Choose viewport (default 1280 x 720) or capture the entire scrollable page height. Pick PNG for lossless or JPEG with quality control for half the size. Sites that block normal headless browsers (anti-bot challenges, fingerprint walls) are automatically retried through our stealth engine: same endpoint, same response shape, you don't have to know which engine ran.

## The hard part

Running a headless browser in production is its own job: keeping the browser up, refreshing fingerprints, recovering from bot challenges, capturing the screenshot at exactly the right moment of the page lifecycle. And then doing it again on the next site that blocks your fingerprint. You ask for an image and get one. We handle which engine, which proxy, and how long to wait.

## Screenshot API: what you get

- Viewport capture in ~2–3 s; full-page in ~2–4 s on typical sites.
- Hostile sites (heavy anti-bot) auto-fall-back to stealth in ~8–12 s.
- PNG or JPEG with 1–100 quality; JPEG is roughly half the byte size at q=70+.
- Full-page mode auto-detects scrollable height up to the rendered page.
- Base64 returned inline (no S3 round-trip, no presigned-URL dance).
- Failures and timeouts don't bill.
- `cookies`, `headers`, `render`, `selector`, `session_id`, and `include_usage` supported: screenshot authenticated pages, target a single element, or reuse a sticky exit IP.

## Screenshot API use cases

- **Visual monitoring**: Capture a page on a schedule and compare the images to catch layout or content changes.
- **Link previews and thumbnails**: A 1280 × 720 viewport capture makes a preview card; JPEG keeps it small.
- **Evidence and archiving**: Full-page captures record what a page showed, with `final_url` and `status_code` alongside.
- **Element shots**: `selector` crops the image to one element, such as a chart or a product card.

## Screenshot API quickstart

Install an SDK with `pip install scrapenest` or `npm install scrapenest`, or call the HTTP API directly with your key in the `Authorization: Bearer` header. No key yet? Sign up free at https://scrapenest.dev/signup, verify your email, then create a key in your dashboard.

### Python SDK

```python
import os
from scrapenest import Client

client = Client(os.environ["SCRAPENEST_API_KEY"], timeout=120)
shot = client.screenshot("https://news.ycombinator.com", viewport_width=1280, viewport_height=720, format="png")
shot.save("screenshot.png")
print(shot.width, shot.height, shot.method, shot.credits_charged, "credits")
```

### Node SDK

```javascript
import { writeFileSync } from "node:fs";
import { ScrapeNest } from "scrapenest";

const client = new ScrapeNest({ apiKey: process.env.SCRAPENEST_API_KEY, timeout: 120_000 });
const shot = await client.screenshot({
  url: "https://news.ycombinator.com",
  viewport_width: 1280,
  viewport_height: 720,
  format: "png",
});
writeFileSync("screenshot.png", Buffer.from(shot.image_base64, "base64"));
console.log(shot.width, shot.height, shot.method, shot.credits_charged, "credits");
```

### curl

```bash
curl -X POST https://scrapenest.dev/v1/scrape/screenshot \
  -H "Authorization: Bearer sn_••••" \
  -H "Content-Type: application/json" \
  -d '{
        "url": "https://news.ycombinator.com",
        "viewport_width": 1280,
        "viewport_height": 720,
        "full_page": false,
        "format": "png"
      }' \
  | jq -r .image_base64 | base64 -d > screenshot.png
```

### Python (httpx)

```python
import base64, httpx

r = httpx.post(
    "https://scrapenest.dev/v1/scrape/screenshot",
    headers={"Authorization": "Bearer sn_••••"},
    json={
        "url": "https://news.ycombinator.com",
        "full_page": True,
        "format": "png",
    },
    timeout=120,
)
r.raise_for_status()
data = r.json()
with open("screenshot.png", "wb") as f:
    f.write(base64.b64decode(data["image_base64"]))
print(f"{data['width']}x{data['height']}, {data['bytes']} bytes")
```

### JavaScript (fetch)

```javascript
import { writeFileSync } from "node:fs";

const r = await fetch("https://scrapenest.dev/v1/scrape/screenshot", {
  method: "POST",
  headers: {
    "Authorization": "Bearer sn_••••",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    url: "https://news.ycombinator.com",
    full_page: true,
    format: "jpeg",
    jpeg_quality: 80,
  }),
});
const data = await r.json();
writeFileSync("screenshot.jpg", Buffer.from(data.image_base64, "base64"));
console.log(`${data.width}x${data.height}, ${data.bytes} bytes`);
```

### Go

```go
package main

import (
    "bytes"
    "encoding/base64"
    "encoding/json"
    "net/http"
    "os"
)

func main() {
    body, _ := json.Marshal(map[string]any{
        "url":       "https://news.ycombinator.com",
        "full_page": true,
        "format":    "png",
    })
    req, _ := http.NewRequest("POST",
        "https://scrapenest.dev/v1/scrape/screenshot", bytes.NewReader(body))
    req.Header.Set("Authorization", "Bearer sn_••••")
    req.Header.Set("Content-Type", "application/json")
    resp, _ := http.DefaultClient.Do(req)
    defer resp.Body.Close()
    var out struct{ ImageBase64 string `json:"image_base64"` }
    json.NewDecoder(resp.Body).Decode(&out)
    img, _ := base64.StdEncoding.DecodeString(out.ImageBase64)
    os.WriteFile("screenshot.png", img, 0644)
}
```

## Screenshot API request and response

### Request body

```json
{
  "url": "https://news.ycombinator.com",
  "viewport_width": 1280,
  "viewport_height": 720,
  "full_page": false,
  "format": "png",
  "wait_extra_ms": 0
}
```

### Response

```json
{
  "url": "https://news.ycombinator.com",
  "final_url": "https://news.ycombinator.com/",
  "status_code": 200,
  "method": "browser",
  "escalated": false,
  "elapsed_ms": 2470,
  "width": 1280,
  "height": 720,
  "bytes": 159284,
  "format": "png",
  "image_base64": "iVBORw0KGgoAAAANSUhEUgAA…",
  "cache_hit": false,
  "credits_charged": 15,
  "proxy_used": null
}
```

Fields with no value are left out of the JSON rather than sent as `null`, so read optional fields defensively. `proxy_used` is the exception: it is always present, `null` included.

## Screenshot API pricing

15 credits for a viewport capture, 25 credits for full-page, 35 credits when the target site only renders through our stealth backend. A `selector`-targeted capture bills 15 (or 35 if the site forces our stealth backend, which doesn't crop to the selector), even with `full_page=true`. A selector that matches nothing returns the full viewport at the requested tier and price. Cache hits bill at 1 credit. Failures don't bill.

- Set `wait_extra_ms` for sites with late-loading content (SPAs that fade in after window.load, lazy-loaded images, charts that mount on idle).
- Hostile sites trigger our stealth backend automatically. You'll see `"method": "stealth"` and `"escalated": true` in the response and the 35-credit charge, no flag to flip.
- Full-page captures of long pages (1080+ rows of content) can produce 1 MB+ PNGs. JPEG with quality 75–85 typically halves that.

## Screenshot API limits

- Viewport: 320 to 3840 wide and 240 to 2160 tall, default 1280 × 720. `device_scale_factor`: 1 to 3, billed the same.
- `jpeg_quality`: 1 to 100, default 85. `wait_extra_ms`: up to 10,000.
- One capture gets 75 seconds across every tier it tries. Past 20 seconds the response streams, so a later error arrives inside the 200 body.
- Caching is off unless you set `cache_ttl_seconds`. Requests with `cookies`, `headers` or `session_id` are never cached.
- `cookies`: up to 50. `headers`: up to 30. `selector`: up to 300 characters.

## Screenshot API error codes

| HTTP | Code | Meaning |
| --- | --- | --- |
| 422 | `selector_not_found` | A `selector` was set and no image could be rendered at all. A selector that only matches nothing returns the full viewport with `selector_applied: false`. |
| 422 | `target_error` | The target returned an HTTP error status, or its host doesn't resolve in DNS. |
| 503 | `screenshot_failed` | The capture failed or ran past 75 seconds. Not billed. |
| 503 | `connection_failed` | The DNS lookup failed temporarily. Retry with backoff. |
| 400 | `unsafe_url` | The URL is malformed or points at a private host. |
| 400 | `redirect_to_unsafe_url` | The page redirected to a private address. |

Every endpoint can also return `401 unauthorized` (missing or wrong key), `402 insufficient_credits` (balance used up), `403 email_not_verified` (an email signup must verify its address before its key works) and `429 rate_limited` or `concurrency_limit_exceeded`. All errors share one JSON envelope; see the [error reference](https://scrapenest.dev/docs#errors).

## Screenshot API FAQ

### How do I take a full-page screenshot?

Set `full_page: true`. The capture covers the page's whole scrollable height and bills 25 credits instead of the 15 for a viewport capture.

### What happens on sites that block headless browsers?

With `render` at `auto` (the default) or `browser`, a capture refused by anti-bot is retried in stealth mode automatically. The response then shows `method: "stealth"` and `escalated: true` and bills 35 credits. If you already know a site is hostile, `render: "stealth"` skips the first attempt.

### Can I screenshot a page behind a login?

Yes. Send `cookies` (a name-to-value map or a list of `{name, value}` objects) and `headers`, and reuse the `session_id` of your scraping calls to keep the same exit IP for about 10 minutes.

### PNG or JPEG?

PNG is lossless and the default. JPEG with `jpeg_quality` between 75 and 85 is typically about half the size, which matters for full-page captures of long pages.

## Related endpoints

- [HTML to PDF API for any URL](https://scrapenest.dev/catalog/pdf.md): `POST /v1/scrape/pdf`. Render any URL to a print-ready PDF — Letter, A4, Legal, and more. Base64 back, anti-bot handled.
- [Web scraping API for any URL](https://scrapenest.dev/catalog/scrape-url.md): `POST /v1/scrape/url`. Point us at a page. We get past the wall and hand back the rendered HTML and clean text.
- [Batch scraping API](https://scrapenest.dev/catalog/scrape-batch.md): `POST /v1/scrape/batch`. Fetch up to 10 URLs in a single request — the same engine as Any URL, run concurrently.

## Get 1,000 free credits

Every account starts on the Free plan: 1,000 credits a month, no card. Verify your email, then mint an API key and make this call. Sign up at https://scrapenest.dev/signup.
