Signing Pro URLs
Every image URL needs your key. A Free key gets 10 renders in total (no monthly reset), with a small "unfurlkit" watermark, and needs no card. Pro ($9/mo or $90/yr, 10,000 renders a month, no watermark, custom fonts (Inter, Roboto, Playfair Display, JetBrains Mono) and logo) uses signed URLs. A valid signature applies your account's plan.
Sign on the server or at build time only. Your secret key must never appear in browser code or in the HTML. The signed URL contains only your public key (k, which looks like pk_...) and the signature (s).
The scheme
| Part | Value |
|---|---|
| URL | https://unfurlkit.com/v1/{template}.png?{params}&k={public_key}&s={signature} |
| Signed string | the request path (e.g. /v1/basic.png) + ? + all query params except s (including k and v if used), sorted by key by UTF-16 code unit (ties broken by value), each key and value RFC 3986-encoded, joined with & |
| Algorithm | HMAC-SHA256, keyed with your secret key as UTF-8 bytes |
| Encoding | base64url (- and _, no padding, not hex), first 16 characters |
The signature covers the exact query string you send. If you change any parameter, sign again.
Templates: basic, blog, product, changelog, repo, event and podcast (each one's params). basic params: title (≤120 chars), subtitle (≤160), theme (dark | light), accent (6-digit hex without #), plus optional v (version / cache-buster). title is required and must be non-empty. Unknown params return 400. A signature that doesn't verify never causes an error status: an unknown key or a bad signature gets the sign-up placeholder (X-Unfurlkit-Error: account_required), and the response has an X-Unfurlkit-Signature header (stale or invalid). A signature made with a rotated-out secret (stale) still renders with the watermark.
Node
import { createHmac } from 'node:crypto';
// RFC 3986: encodeURIComponent leaves !'()* unescaped, so escape them too.
const enc = (s) => encodeURIComponent(s).replace(/[!'()*]/g, (c) => '%' + c.charCodeAt(0).toString(16).toUpperCase());
export function signedOgUrl(params, publicKey, secretKey, path = '/v1/basic.png') {
const query = Object.entries({ ...params, k: publicKey })
.sort(([a, av], [b, bv]) => (a < b ? -1 : a > b ? 1 : av < bv ? -1 : av > bv ? 1 : 0))
.map(([k, v]) => `${enc(k)}=${enc(String(v))}`)
.join('&');
const s = createHmac('sha256', secretKey).update(`${path}?${query}`).digest('base64url').slice(0, 16);
return `https://unfurlkit.com${path}?${query}&s=${s}`;
}
// signedOgUrl({ title: 'Hello', theme: 'dark' }, process.env.UNFURLKIT_PUBLIC_KEY, process.env.UNFURLKIT_SECRET_KEY)
Python
import base64, hashlib, hmac
from urllib.parse import quote
def signed_og_url(params, public_key, secret_key, path="/v1/basic.png"):
# Sort by UTF-16 code units (key, then value) to match the server, including beyond the BMP.
utf16 = lambda x: str(x).encode("utf-16-be")
items = sorted({**params, "k": public_key}.items(), key=lambda kv: (utf16(kv[0]), utf16(kv[1])))
query = "&".join(f"{quote(k, safe='-_.~')}={quote(str(v), safe='-_.~')}" for k, v in items)
digest = hmac.new(secret_key.encode(), f"{path}?{query}".encode(), hashlib.sha256).digest()
s = base64.urlsafe_b64encode(digest).decode().rstrip("=")[:16]
return f"https://unfurlkit.com{path}?{query}&s={s}"
Both snippets produce identical URLs. We tested them against each other and against Unfurlkit's own verification logic with a test key, using titles with spaces, punctuation (! ' ( ) * , & + = / % ~), and non-ASCII characters, plus an emoji key case that checks the UTF-16 sort order.
Tips
- Put the secret in an environment variable (
UNFURLKIT_SECRET_KEY), never in your repo. - Static sites: sign during the build (Eleventy data files, Astro/SvelteKit server code, a Hugo or Ghost pre-build script). The WordPress guide shows the same scheme in PHP.
- Use the same params in the URL that you signed. Don't re-encode or reorder them afterwards.
Rotating a key
- Rotating a key revokes the old secret immediately.
- URLs signed with the old secret that are already published keep rendering, but with the watermark, so your pages don't break, until you re-sign them with the new key.
- Images that are already cached may keep serving until they're purged.
- Need help? We reply within 1 business day at support@unfurlkit.com.
FAQ
Which languages and scripts are supported? Right-to-left scripts such as Arabic and Hebrew aren't supported yet at launch.
See Unfurlkit pricing · Check any page with the Free OG Image Checker.