How do I get a link preview for a URL?
Request the page with response_type=json. Shotfly renders it, reads the title, description, Open Graph image, site name and favicon from the page, and returns them with a link to a thumbnail. Use the page's own og:image when it has one, and the thumbnail when it doesn't.
const target = 'https://example.com'
const params = new URLSearchParams({ url: target, response_type: 'json', thumbnail_width: '400' })
const res = await fetch(`https://api.shotfly.dev/v1/screenshot?${params}`, {
headers: { Authorization: `Bearer ${process.env.SHOTFLY_SECRET_KEY}` },
})
const body = await res.json()
if (!res.ok) throw new Error(`${body.error.code}: ${body.error.message}`)
const m = body.metadata ?? {}
const preview = {
url: m.canonical ?? target,
title: m.title ?? new URL(target).hostname,
description: m.description ?? '',
// The page's own image if it has one, else the thumbnail (the link expires in one hour).
image: m.image ?? body.url,
favicon: m.favicon,
siteName: m.siteName,
}
console.log(preview)Which fields does the JSON response have?
| Field | What it holds |
|---|---|
url, url_expires_at | A link to the image, valid for one hour |
width, height, bytes, content_type | The image |
credits_charged, cache | What the request cost (0 for a cache hit), and hit or miss |
metadata.title | og:title, or the page title |
metadata.description | og:description, or the meta description |
metadata.image | og:image, or twitter:image |
metadata.siteName, metadata.type | og:site_name and og:type |
metadata.url, metadata.canonical | og:url (or the final page address) and <link rel="canonical"> |
metadata.favicon | <link rel="icon">, or /favicon.ico |
metadata.lang, metadata.themeColor | <html lang> and the theme-color meta tag |
Fields the page doesn't have are left out, and metadata is null when Shotfly could not read any.
Can I put the preview image straight into my page?
Yes, with a signed URL. Sign the parameters with your secret on your server and use the result in <img src>: the URL carries your public key (pk_โฆ) and a signature, never the secret. Signed images are served with a public Cache-Control header, so browsers and CDNs can keep them. The signing function is on authentication and signed URLs.
How fresh are previews, and what do they cost?
A preview costs 1 credit when it succeeds. Results are cached for cache_ttl seconds (one day by default, up to 30 days), and cache hits are free. Pass fresh=true to render the page again, for example after a user edits it.
What are the limits?
- The metadata is whatever the page declares. Tags that a script adds late may need
wait_for_selector. - The
urllink expires after one hour: copy the image to your own storage, or use a signed URL. - Sites that block automated browsers fail with
target_blockedand cost nothing. - Every preview is a browser render, which takes longer than reading the HTML alone. Fetch previews in the background rather than while the user waits.

GitHub