Code Examples
Copy-paste examples in cURL, JavaScript, Python, and Go.
Basic Screenshot
Capture a simple PNG screenshot of any URL:
curl -X POST https://api.getsnap.dev/v1/screenshot \
-H "X-API-Key: sk_live_YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{
"url": "https://github.com",
"format": "png"
}'
const response = await fetch("https://api.getsnap.dev/v1/screenshot", {
method: "POST",
headers: {
"X-API-Key": "sk_live_YOUR_KEY",
"Content-Type": "application/json",
},
body: JSON.stringify({
url: "https://github.com",
format: "png",
}),
});
const data = await response.json();
console.log(data.url); // CDN URL to your screenshot
import requests
response = requests.post(
"https://api.getsnap.dev/v1/screenshot",
headers={
"X-API-Key": "sk_live_YOUR_KEY",
"Content-Type": "application/json",
},
json={
"url": "https://github.com",
"format": "png",
},
)
data = response.json()
print(data["url"]) # CDN URL to your screenshot
package main
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
)
func main() {
body, _ := json.Marshal(map[string]interface{}{
"url": "https://github.com",
"format": "png",
})
req, _ := http.NewRequest("POST",
"https://api.getsnap.dev/v1/screenshot",
bytes.NewBuffer(body))
req.Header.Set("X-API-Key", "sk_live_YOUR_KEY")
req.Header.Set("Content-Type", "application/json")
resp, _ := http.DefaultClient.Do(req)
defer resp.Body.Close()
var result map[string]interface{}
json.NewDecoder(resp.Body).Decode(&result)
fmt.Println(result["url"])
}
Full Page Capture
Capture the entire scrollable page, not just the viewport:
curl -X POST https://api.getsnap.dev/v1/screenshot \
-H "X-API-Key: sk_live_YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{
"url": "https://stripe.com/docs",
"format": "png",
"full_page": true,
"remove_popups": true
}'
const data = await fetch("https://api.getsnap.dev/v1/screenshot", {
method: "POST",
headers: {
"X-API-Key": "sk_live_YOUR_KEY",
"Content-Type": "application/json",
},
body: JSON.stringify({
url: "https://stripe.com/docs",
format: "png",
full_page: true,
remove_popups: true,
}),
}).then(r => r.json());
console.log(data.url);
response = requests.post(
"https://api.getsnap.dev/v1/screenshot",
headers={"X-API-Key": "sk_live_YOUR_KEY", "Content-Type": "application/json"},
json={
"url": "https://stripe.com/docs",
"format": "png",
"full_page": True,
"remove_popups": True,
},
)
print(response.json()["url"])
PDF Generation
Generate a PDF of any webpage — perfect for invoices, reports, or archival:
curl -X POST https://api.getsnap.dev/v1/screenshot \
-H "X-API-Key: sk_live_YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{
"url": "https://invoice.example.com/inv-001",
"format": "pdf",
"full_page": true
}'
const { url } = await fetch("https://api.getsnap.dev/v1/screenshot", {
method: "POST",
headers: {
"X-API-Key": "sk_live_YOUR_KEY",
"Content-Type": "application/json",
},
body: JSON.stringify({
url: "https://invoice.example.com/inv-001",
format: "pdf",
full_page: true,
}),
}).then(r => r.json());
// url contains the CDN link to the generated PDF
Mobile Device Emulation
Capture as seen on a mobile or tablet device:
curl -X POST https://api.getsnap.dev/v1/screenshot \
-H "X-API-Key: sk_live_YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{
"url": "https://tailwindcss.com",
"format": "webp",
"device": "mobile",
"quality": 90
}'
const data = await fetch("https://api.getsnap.dev/v1/screenshot", {
method: "POST",
headers: {
"X-API-Key": "sk_live_YOUR_KEY",
"Content-Type": "application/json",
},
body: JSON.stringify({
url: "https://tailwindcss.com",
format: "webp",
device: "mobile",
quality: 90,
}),
}).then(r => r.json());
Element Capture (CSS Selector)
Capture a specific element on the page using a CSS selector:
curl -X POST https://api.getsnap.dev/v1/screenshot \
-H "X-API-Key: sk_live_YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{
"url": "https://getsnap.dev",
"format": "png",
"selector": "#pricing .price-card.featured"
}'
const data = await fetch("https://api.getsnap.dev/v1/screenshot", {
method: "POST",
headers: {
"X-API-Key": "sk_live_YOUR_KEY",
"Content-Type": "application/json",
},
body: JSON.stringify({
url: "https://getsnap.dev",
format: "png",
selector: "#pricing .price-card.featured",
}),
}).then(r => r.json());
Custom CSS Injection
Inject custom CSS before capture — hide elements, change styles, or highlight sections:
curl -X POST https://api.getsnap.dev/v1/screenshot \
-H "X-API-Key: sk_live_YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{
"url": "https://news.ycombinator.com",
"format": "png",
"css": "header { display: none; } body { padding-top: 0; }",
"full_page": false
}'
Dark Mode
Trigger dark mode on sites that support prefers-color-scheme:
curl -X POST https://api.getsnap.dev/v1/screenshot \
-H "X-API-Key: sk_live_YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{
"url": "https://github.com",
"format": "png",
"dark_mode": true
}'
Binary Response (Direct Download)
Get the raw image bytes instead of a CDN URL. Useful for processing or immediate display:
# Save directly to a file
curl -X POST https://api.getsnap.dev/v1/screenshot \
-H "X-API-Key: sk_live_YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{
"url": "https://example.com",
"format": "png",
"response_type": "binary"
}' \
--output screenshot.png
import { writeFile } from "fs/promises";
const response = await fetch("https://api.getsnap.dev/v1/screenshot", {
method: "POST",
headers: {
"X-API-Key": "sk_live_YOUR_KEY",
"Content-Type": "application/json",
},
body: JSON.stringify({
url: "https://example.com",
format: "png",
response_type: "binary",
}),
});
const buffer = Buffer.from(await response.arrayBuffer());
await writeFile("screenshot.png", buffer);
console.log("Saved screenshot.png");
response = requests.post(
"https://api.getsnap.dev/v1/screenshot",
headers={"X-API-Key": "sk_live_YOUR_KEY", "Content-Type": "application/json"},
json={
"url": "https://example.com",
"format": "png",
"response_type": "binary",
},
)
with open("screenshot.png", "wb") as f:
f.write(response.content)
print("Saved screenshot.png")