Screenshot API
Capture any URL or raw HTML as a PNG, JPEG, or WebP — full-page, device-emulated, dark-mode aware, with ads and cookie banners stripped.
POST /v1/screenshot → Binary image (image/png, image/jpeg, or image/webp)
Example
curl -X POST https://rasterkit.com/v1/screenshot \
-H "x-api-key: $RASTERKIT_API_KEY" \
-H "content-type: application/json" \
-d '{"url": "https://example.com", "full_page": true, "format": "png"}' \
-o screenshot.png import { writeFile } from 'node:fs/promises'
const res = await fetch('https://rasterkit.com/v1/screenshot', {
method: 'POST',
headers: {
'x-api-key': process.env.RASTERKIT_API_KEY,
'content-type': 'application/json',
},
body: JSON.stringify({"url": "https://example.com", "full_page": true, "format": "png"}),
})
if (!res.ok) throw new Error(`Render failed: ${res.status} ${await res.text()}`)
await writeFile('screenshot.png', Buffer.from(await res.arrayBuffer()))
console.log('Saved screenshot.png') import os
import requests
res = requests.post(
"https://rasterkit.com/v1/screenshot",
headers={"x-api-key": os.environ["RASTERKIT_API_KEY"]},
json={"url": "https://example.com", "full_page": True, "format": "png"},
timeout=60,
)
res.raise_for_status()
with open("screenshot.png", "wb") as f:
f.write(res.content)
print("Saved screenshot.png") <?php
$ch = curl_init('https://rasterkit.com/v1/screenshot');
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 60,
CURLOPT_HTTPHEADER => [
'x-api-key: ' . getenv('RASTERKIT_API_KEY'),
'content-type: application/json',
],
CURLOPT_POSTFIELDS => '{"url": "https://example.com", "full_page": true, "format": "png"}',
]);
$body = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
curl_close($ch);
if ($status !== 200) {
throw new RuntimeException("Render failed: $status $body");
}
file_put_contents('screenshot.png', $body);
echo "Saved screenshot.png\n"; require "net/http"
require "json"
uri = URI("https://rasterkit.com/v1/screenshot")
req = Net::HTTP::Post.new(uri)
req["x-api-key"] = ENV.fetch("RASTERKIT_API_KEY")
req["content-type"] = "application/json"
req.body = '{"url": "https://example.com", "full_page": true, "format": "png"}'
res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true, read_timeout: 60) { |http| http.request(req) }
raise "Render failed: #{res.code} #{res.body}" unless res.code == "200"
File.binwrite("screenshot.png", res.body)
puts "Saved screenshot.png" package main
import (
"bytes"
"fmt"
"io"
"net/http"
"os"
"time"
)
func main() {
body := []byte(`{"url": "https://example.com", "full_page": true, "format": "png"}`)
req, _ := http.NewRequest("POST", "https://rasterkit.com/v1/screenshot", bytes.NewReader(body))
req.Header.Set("x-api-key", os.Getenv("RASTERKIT_API_KEY"))
req.Header.Set("content-type", "application/json")
client := &http.Client{Timeout: 60 * time.Second}
res, err := client.Do(req)
if err != nil {
panic(err)
}
defer res.Body.Close()
data, _ := io.ReadAll(res.Body)
if res.StatusCode != 200 {
panic(fmt.Sprintf("render failed: %d %s", res.StatusCode, data))
}
os.WriteFile("screenshot.png", data, 0644)
fmt.Println("Saved screenshot.png")
} import java.net.URI;
import java.net.http.*;
import java.nio.file.*;
import java.time.Duration;
public class Render {
public static void main(String[] args) throws Exception {
String body = """
{"url": "https://example.com", "full_page": true, "format": "png"}""";
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://rasterkit.com/v1/screenshot"))
.timeout(Duration.ofSeconds(60))
.header("x-api-key", System.getenv("RASTERKIT_API_KEY"))
.header("content-type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(body))
.build();
HttpResponse<byte[]> res = HttpClient.newHttpClient()
.send(request, HttpResponse.BodyHandlers.ofByteArray());
if (res.statusCode() != 200) {
throw new RuntimeException("Render failed: " + res.statusCode() + " " + new String(res.body()));
}
Files.write(Path.of("screenshot.png"), res.body());
System.out.println("Saved screenshot.png");
}
} using System.Text;
var client = new HttpClient { Timeout = TimeSpan.FromSeconds(60) };
client.DefaultRequestHeaders.Add("x-api-key",
Environment.GetEnvironmentVariable("RASTERKIT_API_KEY"));
var body = new StringContent(
"""{"url": "https://example.com", "full_page": true, "format": "png"}""",
Encoding.UTF8, "application/json");
var res = await client.PostAsync("https://rasterkit.com/v1/screenshot", body);
var bytes = await res.Content.ReadAsByteArrayAsync();
if (!res.IsSuccessStatusCode)
throw new Exception($"Render failed: {(int)res.StatusCode} {Encoding.UTF8.GetString(bytes)}");
await File.WriteAllBytesAsync("screenshot.png", bytes);
Console.WriteLine("Saved screenshot.png"); Parameters
Send as a JSON body. Exactly the same fields work as query parameters on the signed GET variant.
| Parameter | Type | Default | Description |
|---|---|---|---|
url | url | — | Page to capture. Exactly one of url or html. |
html | string ≤2MB | — | Raw HTML to render instead of a URL. |
viewport_width | int 64–3840 | 1280 | Viewport width in CSS pixels. |
viewport_height | int 64–2160 | 800 | Viewport height in CSS pixels. |
device_scale_factor | number 1–3 | 1 | Retina scaling (2 = @2x output). |
full_page | bool | false | Capture the entire scroll height (lazy content is auto-scrolled in). |
format | png | jpeg | webp | png | Output encoding. |
quality | int 1–100 | 80 | jpeg/webp quality. Ignored for png. |
device | desktop | mobile | tablet | desktop | Realistic device presets (viewport, UA, touch). |
dark_mode | bool | false | Emulate prefers-color-scheme: dark. |
block_ads | bool | true | Block common ad/tracker domains for cleaner, faster captures. |
block_cookie_banners | bool | true | Hide common consent popups (OneTrust, Cookiebot, …). |
delay_ms | int 0–10000 | 0 | Extra wait after load, for animations or late JS. |
wait_until | load | domcontentloaded | networkidle | load | Navigation settled condition before capture. |
wait_for_selector | string | — | Block until this CSS selector is visible. |
timeout_ms | int 1000–60000 | 30000 | Hard cap for navigation + capture. |
cache_ttl | int 0–604800 (s) | 0 | Cache the result; identical requests within the TTL are served free and instantly. |
async | bool | false | Return 202 + job id immediately instead of waiting. |
webhook_url | url | — | POSTed (signed) when an async job finishes. |
Responses
- 200 — the binary result. Headers include
x-rasterkit-cache: HIT|MISSandx-rasterkit-render-ms. - 202 — when
async: true; body is{ "id", "status", "status_url" }. See async jobs. - 4xx/5xx — JSON envelope
{ "error": { "code", "message", "docs" } }. Full catalog: errors.
Tips
- For app-like pages that render late, combine
wait_until: "networkidle"withwait_for_selector. full_page: trueauto-scrolls first so lazy-loaded images are present.- Use
device: "mobile"for a real iPhone-class viewport, UA, and touch emulation. - Set
cache_ttl: 86400for link-preview workloads — repeat captures of the same URL are then free and instant.