Code Examples

Copy-paste examples to start generating screenshots in seconds. Replace sk_your_api_key with your actual API key.

Basic Screenshot

Capture a post and save it as a PNG file.

1# Save a tweet screenshot to screenshot.png
2curl -o screenshot.png \
3 "https://postcapture.com/api/screenshot?postUrl=https://x.com/postcaboron/status/1924847327370461555&apiKey=sk_your_api_key"

Custom Settings

Customize the screenshot appearance with additional query parameters.

1# Dark theme, no watermark, hide follower count
2curl -o screenshot.png \
3 "https://postcapture.com/api/screenshot?\
4postUrl=https://x.com/postcaboron/status/1924847327370461555&\
5apiKey=sk_your_api_key&\
6theme=dark&\
7showWatermark=false&\
8showFollowerCount=false&\
9padding=50&\
10scaleFactor=3"

Multi-Platform

The same endpoint works for all supported platforms. Just change the postUrl.

1# Twitter / X
2curl -o twitter.png "https://postcapture.com/api/screenshot?postUrl=https://x.com/postcaboron/status/1924847327370461555&apiKey=sk_your_api_key"
3
4# YouTube
5curl -o youtube.png "https://postcapture.com/api/screenshot?postUrl=https://youtube.com/watch?v=dQw4w9WgXcQ&apiKey=sk_your_api_key"
6
7# TikTok
8curl -o tiktok.png "https://postcapture.com/api/screenshot?postUrl=https://tiktok.com/@user/video/1234567890&apiKey=sk_your_api_key"
9
10# Bluesky
11curl -o bluesky.png "https://postcapture.com/api/screenshot?postUrl=https://bsky.app/profile/user.bsky.social/post/abc123&apiKey=sk_your_api_key"

Batch Processing with Rate Limit Handling

Process many URLs while respecting the 10 requests/minute rate limit.

1import { writeFile } from "node:fs/promises";
2
3const API_KEY = process.env.POSTCAPTURE_API_KEY;
4const DELAY_MS = 7000; // ~8.5 requests/min to stay under the limit
5
6const urls = [
7 "https://x.com/postcaboron/status/1924847327370461555",
8 "https://x.com/elonmusk/status/1234567890",
9 // ... more URLs
10];
11
12async function captureOne(postUrl, index) {
13 const url = new URL("https://postcapture.com/api/screenshot");
14 url.searchParams.set("postUrl", postUrl);
15 url.searchParams.set("apiKey", API_KEY);
16
17 const res = await fetch(url);
18
19 if (res.status === 429) {
20 const wait = parseInt(res.headers.get("Retry-After") || "10");
21 console.log(`Rate limited. Waiting ${wait}s…`);
22 await new Promise((r) => setTimeout(r, wait * 1000));
23 return captureOne(postUrl, index); // retry
24 }
25
26 if (!res.ok) throw new Error(`${res.status} for ${postUrl}`);
27
28 const file = `screenshot-${index}.png`;
29 await writeFile(file, Buffer.from(await res.arrayBuffer()));
30 console.log(`[${index + 1}/${urls.length}] Saved ${file}`);
31}
32
33for (let i = 0; i < urls.length; i++) {
34 await captureOne(urls[i], i);
35 if (i < urls.length - 1) {
36 await new Promise((r) => setTimeout(r, DELAY_MS));
37 }
38}
39
40console.log("Done!");