Integrate Context.dev's Screenshot API in your app
Prerequisites
-
A Context.dev API key. Sign up at context.dev/signup, copy the key from the dashboard (prefix
ctxt_secret_), and export it: -
An SDK (optional). Install for your language, or skip the install and call directly with
curl:
Capture a screenshot
There are two ways to point at the page you want to capture:- Give a specific URL: pass
directUrlwith the full URL (e.g.https://stripe.com/pricing). - Give a domain and a page type: pass
domain(e.g.stripe.com) for the homepage. Add apagetype (choose fromlogin,signup,blog,careers,pricing,terms,privacy, orcontact) to let Context.dev’s resolver find the right URL on the domain.
handleCookiePopup is set to "true"), takes a screenshot, uploads it to a CDN and returns the public URL.
Captures are cached for one day by default; pass
maxAgeMs: 0 to force a
fresh render, or up to 30 days for longer reuse.Request Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
domain | string | — | Required unless directUrl is provided. Domain to screenshot (e.g. stripe.com). |
directUrl | string (URI) | — | Required unless domain is provided. Exact URL to screenshot. |
fullScreenshot | string enum ("true" / "false") | "false" | "true" captures the full scrollable height; otherwise a single viewport frame. |
handleCookiePopup | string enum ("true" / "false") | "false" | When "true", dismisses the cookie/consent banner before capture. |
viewport | object { width, height } | { width: 1920, height: 1080 } | Browser viewport in pixels. width 240–7680, height 240–4320. |
page | enum (login / signup / blog / careers / pricing / terms / privacy / contact) | — | Resolve the right URL for the page type via link-scraping heuristics. Only valid with domain, not directUrl. |
maxAgeMs | integer | 86400000 (1 day) | Return a cached capture younger than this. 0 forces fresh. Max 2592000000 (30 days). |
waitForMs | integer | 3000 | Browser wait after page load before capture. Min 0, max 30000 (30 seconds). |
timeoutMS | integer | — | Abort with 408 if the request exceeds this many milliseconds. Min 1000, max 300000 (5 min). |
Response
| Field | Type | Description |
|---|---|---|
status | string | "ok" on success. |
code | integer | HTTP status code, echoed for convenience. |
domain | string | Normalized domain that was processed. For directUrl requests, the host parsed out of the URL. |
screenshot | string | Public CDN URL of the captured PNG. Content-addressed: the same query against the same target returns the same URL until maxAgeMs expires. |
screenshotType | enum | "viewport" or "fullPage". Mirrors what was actually captured. |
width | integer | Width of the captured image in pixels. |
height | integer | Height in pixels. With fullScreenshot: "true", this is the full scrollable height (often 5–20× the viewport). |
Handle errors
The endpoint surfaces four failure modes:| Status | Meaning | What to do |
|---|---|---|
| 400 | Validation error: neither domain nor directUrl provided, both provided at once, page combined with directUrl, or a malformed value | Surface as a user-facing error. The response body’s error_code distinguishes INPUT_VALIDATION_ERROR, WEBSITE_ACCESS_ERROR, etc. |
| 401 | Missing or invalid API key | Re-check the env var and the dashboard. |
| 408 | REQUEST_TIMEOUT: the page didn’t render before timeoutMS elapsed (typically a cold hit) | Retry once with backoff, or prefetch the capture ahead of time. |
| 500 | Transient renderer or server error | Retry with exponential backoff. |
Use cases
- Auto-generate on-brand campaign and preview images for every page.
- Give your coding agent screenshotting tools to do QA or classification tasks.
- Archive dated visual snapshots of pages for compliance or audits.
- Power server-side link-preview / share-card generation for chat apps, comments, and any paste-a-URL flow.
Next steps
Prefetch for Faster Response
Hide cold-hit latency from your users.
Handle Rate Limits
Backoff strategies, client cache, and prefetch fallbacks.
Best Practices
Caching, error handling, and key hygiene.
Troubleshooting
Status codes, retry patterns, and common errors.