API Reference
Preview API
A simplified screenshot endpoint designed for use directly from the browser. No template setup required — pass your client key and a URL, get back a 1200×630 PNG.
Browser-only endpoint
Origin header for authentication. It is intended for use from your website's JavaScript — not from server-side code or curl. For server-side use, use the OG Screenshot API instead.Endpoint#
/api/preview/:clientKey?url=<targetUrl>Returns a 1200×630 PNG screenshot of the target URL. Authentication is via client key (URL path) and Origin header (CORS).
Authentication#
Requests are authenticated using two values:
- Client key — a unique key assigned to your account, embedded directly in the URL path. Find yours in Dashboard → Previews. Format:
cl_followed by 24 hexadecimal characters (e.g.,cl_a1b2c3d4e5f6a1b2c3d4e5f6). - Origin header — sent automatically by browsers when making cross-origin requests. The origin must match a domain you have registered. Linkshot responds with an
Access-Control-Allow-Originheader scoped to that specific origin.
Localhost bypass
localhost or 127.0.0.1 skip all authentication checks. This makes local development seamless — no need to register a localhost domain.Parameters#
| Parameter | Type | In | Description | |
|---|---|---|---|---|
clientKey* | string | path | — | Your account's client key. Format: cl_ followed by 24 hex chars. Found in Dashboard → Previews. |
url* | string (URL) | query | — | The fully-qualified URL of the page to screenshot. Must be on a domain you have registered (except localhost). |
Origin* | string | header | — | Sent automatically by browsers. Must match a domain in your registered domain list. |
Capture Settings#
The Preview API uses fixed capture settings optimized for OG images. These cannot be customized — use the OG Screenshot API with a template for full control.
| Setting | Value |
|---|---|
viewportWidth | 1200px |
viewportHeight | 630px |
deviceScaleFactor | 2 (retina) |
enableTailwindInjection | false |
waitTimeout | 0ms |
blockPopups | true |
CORS#
The endpoint supports CORS preflight (OPTIONS) and returns origin-specific CORS headers.
Access-Control-Allow-Origin: https://example.com
Access-Control-Allow-Methods: GET, OPTIONS
Access-Control-Allow-Headers: Content-Type
Access-Control-Max-Age: 86400
Vary: Origin
Content-Type: image/png
Cache-Control: public, s-maxage=43200, stale-while-revalidate=43200
X-Cache: HIT | MISSCaching#
Preview screenshots are cached, keyed by preview/{sha256(url)}.
- TTL:
s-maxage=43200(12 hours). - Background regeneration triggers when the cached object is older than 24 hours, so stale images are refreshed automatically.
Examples#
const clientKey = 'cl_a1b2c3d4e5f6a1b2c3d4e5f6'
const targetUrl = encodeURIComponent('https://example.com/blog/my-post')
const response = await fetch(
`https://uselinkshot.com/api/preview/${clientKey}?url=${targetUrl}`
)
if (response.ok) {
const blob = await response.blob()
const imageUrl = URL.createObjectURL(blob)
document.querySelector('#preview-img').src = imageUrl
}<img
src="https://uselinkshot.com/api/preview/cl_YOUR_KEY?url=https%3A%2F%2Fexample.com"
alt="Page preview"
width="1200"
height="630"
/>URL-encode the target URL
url parameter using encodeURIComponent().Error Responses#
All errors return JSON with an error and message field.
{
"error": "missing_origin",
"message": "Origin header is required. This endpoint is intended for browser use only."
}{
"error": "invalid_origin",
"message": "The Origin header is not a valid URL"
}{
"error": "missing_url",
"message": "Please provide a url query parameter"
}{
"error": "invalid_url",
"message": "The provided url is not a valid URL"
}{
"error": "invalid_client_key",
"message": "The provided client key is not valid"
}{
"error": "origin_not_authorized",
"message": "The origin \"example.com\" is not in your registered domain list"
}{
"error": "no_active_subscription",
"message": "No active subscription found for this client key"
}{
"error": "navigation_timeout",
"message": "Page failed to load within timeout: https://example.com/page"
}{
"error": "screenshot_failed",
"message": "Screenshot generation failed: <error detail>"
}