How to Take Website Screenshots with an API in 2026
Need to capture website screenshots programmatically? Whether you're building social media preview images, generating PDF reports, or doing visual regression testing, a screenshot API saves you from running your own browser infrastructure.
In this guide, we'll show you how to capture pixel-perfect screenshots using SnapAPI with code examples in cURL, Python, and JavaScript.
Why Use a Screenshot API?
Running headless browsers (Puppeteer, Playwright, Selenium) yourself means:
- Managing browser installations and updates
- Handling memory leaks and zombie processes
- Scaling infrastructure for concurrent requests
- Dealing with timeouts, crashes, and edge cases
A screenshot API handles all of this. You send a URL, you get an image back. That's it.
Quick Start: Your First Screenshot in 30 Seconds
1. Get a Free API Key
curl -X POST https://api.usesnapapi.com/v1/keys \
-H "Content-Type: application/json" \
-d '{"email": "you@example.com"}'
This gives you an API key instantly. No credit card, no signup form. 500 free screenshots per month.
2. Capture a Screenshot
curl -X POST https://api.usesnapapi.com/v1/screenshot \
-H "Authorization: Bearer snap_your_key_here" \
-H "Content-Type: application/json" \
-d '{"url": "https://github.com"}' \
-o screenshot.png
That's it. You now have a 1280x720 PNG screenshot of GitHub.
Python Example
import requests
API_KEY = "snap_your_key_here"
API_URL = "https://api.usesnapapi.com/v1/screenshot"
response = requests.post(API_URL,
headers={
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json"
},
json={
"url": "https://news.ycombinator.com",
"width": 1280,
"height": 720,
"full_page": False
}
)
with open("screenshot.png", "wb") as f:
f.write(response.content)
print(f"Screenshot saved! ({len(response.content)} bytes)")
JavaScript / Node.js Example
const fs = require('fs');
async function takeScreenshot(url) {
const response = await fetch('https://api.usesnapapi.com/v1/screenshot', {
method: 'POST',
headers: {
'Authorization': 'Bearer snap_your_key_here',
'Content-Type': 'application/json'
},
body: JSON.stringify({
url,
width: 1280,
height: 720,
format: 'png'
})
});
const buffer = Buffer.from(await response.arrayBuffer());
fs.writeFileSync('screenshot.png', buffer);
console.log(`Screenshot saved! (${buffer.length} bytes)`);
}
takeScreenshot('https://news.ycombinator.com');
Advanced Options
Full-Page Screenshots
Capture the entire scrollable page, not just the viewport:
{
"url": "https://example.com",
"full_page": true
}
Dark Mode
Sites that support prefers-color-scheme will render in dark mode:
{
"url": "https://github.com",
"dark_mode": true
}
Retina / HiDPI
Get crystal-clear 2x or 3x resolution screenshots:
{
"url": "https://example.com",
"device_scale_factor": 2.0
}
Element Capture
Capture a specific element on the page using CSS selectors:
{
"url": "https://example.com",
"selector": "#main-content"
}
HTML to Screenshot
Render your own HTML instead of a URL — perfect for generating OG images, reports, or receipts:
{
"html": "<div style='padding:40px;background:#6366f1;color:white;font-size:48px'>Hello World</div>",
"width": 1200,
"height": 630
}
Generate PDFs Too
SnapAPI also converts any URL or HTML to PDF:
curl -X POST https://api.usesnapapi.com/v1/pdf \
-H "Authorization: Bearer snap_your_key_here" \
-H "Content-Type: application/json" \
-d '{
"url": "https://example.com",
"format": "A4",
"print_background": true
}' \
-o output.pdf
Common Use Cases
- Social media previews — Generate OG images dynamically for your pages
- Invoice generation — HTML template to PDF in one API call
- Visual regression testing — Compare screenshots before and after deployments
- Web archiving — Capture pages for compliance or records
- Dashboard reports — Convert dashboards to PDF for stakeholders
- E-commerce — Product page screenshots for marketplaces
Pricing
SnapAPI is free to start. Paid plans scale with your usage:
- Free — 500 screenshots/month, all features
- Starter ($9/mo) — 5,000 screenshots/month
- Pro ($29/mo) — 25,000 screenshots/month
- Business ($79/mo) — 100,000 screenshots/month
Compare that to ScreenshotOne ($17/mo for 1,500), Urlbox ($99/mo), or running your own Puppeteer infrastructure.