Docs

Cardboard turns a card you design once into an image URL per page. Social sites fetch the PNG from that URL when someone shares the page.

Quick start

  1. Sign in and create a card, or start from a template.
  2. Select the text or image that changes per page and turn on “Changes per card”.
  3. Save, then open Share to copy a link, the meta tags, or a code example.
  4. For links built in your own code, copy your signing key from the dashboard.

Card URLs

Every card URL has the same shape:

https://api.cardboard.ayooluwa.me/api/card/<template-id>?<field>=<value>&s=<signature>
  • The template id comes from the editor (Share → In your code).
  • Fields are URL-encoded and sorted by name; the same values always give the same URL.
  • s is the signature. It is required and covers the template id and every field.
  • The response is a 1200×630 PNG.

Fields

A field is a text or image layer with “Changes per card” turned on. Its field name is the URL parameter. Leave a field out and the card shows what was typed in the editor. Image fields take an https:// link to a PNG, JPEG, WebP or GIF.

Signing keys

Links are signed so nobody can put their own words on your design. Your signing key is in the dashboard. Keep it on your server, as an environment variable such as CARDBOARD_SIGNING_KEY; never ship it to the browser. Regenerating the key invalidates every link signed with the old one.

cardboard-url

npm install cardboard-url
import { buildCardUrl } from 'cardboard-url';

const image = buildCardUrl({
  baseUrl: 'https://api.cardboard.ayooluwa.me',
  templateId: 'your-template-id',
  secret: process.env.CARDBOARD_SIGNING_KEY,
  fields: { title: post.title },
});

It runs on Node.js 18 or later and throws a clear error if the key is missing. Next.js users can return the URL from generateMetadata as an Open Graph image.

Framework guides

Sign links on the server, where your signing key lives, and put them in the page's head. Each guide uses cardboard-url; replace getPost with however your site loads a page.

app/blog/[slug]/page.tsx
import type { Metadata } from 'next';
import { buildCardUrl } from 'cardboard-url';

export async function generateMetadata({
  params,
}: {
  params: Promise<{ slug: string }>;
}): Promise<Metadata> {
  const post = await getPost((await params).slug);
  const image = buildCardUrl({
    baseUrl: 'https://api.cardboard.ayooluwa.me',
    templateId: 'your-template-id',
    secret: process.env.CARDBOARD_SIGNING_KEY,
    fields: { title: post.title },
  });
  return {
    title: post.title,
    openGraph: { images: [{ url: image, width: 1200, height: 630 }] },
    twitter: { card: 'summary_large_image', images: [image] },
  };
}

Sites rendered only in the browser, like a plain React or Vue app, can't give each page its own preview: social sites don't run JavaScript when they fetch a link. Use one of the frameworks above, or put one link copied from the editor in index.html.

Without the package

The package is optional. Every link needs its signature, but there are three ways to get one.

Copy the link from the editor

Fill in the fields in the editor, open Share and copy the image link. It comes signed, so it can go straight into a page's og:image tag. This suits pages whose text rarely changes, like a home, about or landing page.

Sign links in any language

The signature is an HMAC-SHA256 of the template id, a line break, and the fields sorted by name, URL-encoded and joined as key=value&key=value. It is made with your signing key, encoded as base64url without padding, and added as s. The one detail to match is the URL-encoding: it must match JavaScript's encodeURIComponent, which leaves letters, digits and - _ . ! ~ * ' ( ) as they are and encodes everything else, spaces as %20. Ready-made versions for Python, Ruby, PHP, Go and Java are under Other languages.

Cards without fields

If a template has no fields, its link signs only the template id. Copy it once from the editor and reuse it everywhere.

Other languages

Each guide has a small signing function to copy into your project, and an example of using it. They produce exactly the same links as cardboard-url.

Flask and FastAPI work the same way: build the link in the route and pass it to the template.

cardboard.py
import base64
import hashlib
import hmac
from urllib.parse import quote

CARDBOARD_API = "https://api.cardboard.ayooluwa.me"


def card_url(template_id: str, fields: dict[str, str], secret: str) -> str:
    def encode(value: str) -> str:
        return quote(value, safe="-_.!~*'()")

    query = "&".join(f"{encode(k)}={encode(fields[k])}" for k in sorted(fields))
    message = f"{template_id}\n{query}".encode()
    digest = hmac.new(secret.encode(), message, hashlib.sha256).digest()
    signature = base64.urlsafe_b64encode(digest).rstrip(b"=").decode()
    prefix = f"{query}&" if query else ""
    return f"{CARDBOARD_API}/api/card/{template_id}?{prefix}s={signature}"
blog/views.py (Django)
import os

from django.shortcuts import get_object_or_404, render

from cardboard import card_url


def post_detail(request, slug):
    post = get_object_or_404(Post, slug=slug)
    image = card_url("your-template-id", {"title": post.title}, os.environ["CARDBOARD_SIGNING_KEY"])
    return render(request, "blog/post.html", {"post": post, "card_image": image})
blog/templates/blog/post.html
<meta property="og:image" content="{{ card_image }}">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="{{ card_image }}">

Meta tags

<meta property="og:image" content="IMAGE_URL" />
<meta property="og:image:width" content="1200" />
<meta property="og:image:height" content="630" />
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:image" content="IMAGE_URL" />

In HTML, write & as &amp; inside the attribute. The Share dialog does this for you.

Caching

Each image is rendered once and cached by template, template version and field values. Repeat requests come from memory or storage in milliseconds. Saving the template starts a new version, so links show the new design without changing. Responses are cacheable for an hour by browsers and a day by CDNs.

Images

Uploaded images are stored privately. Image links passed as field values must be public https:// URLs without a custom port, at most 5 MB, and respond within 3 seconds. Links to private or internal addresses are refused.

Errors and limits

  • 403: missing or wrong signature (edited link, or an old signing key).
  • 404: the template doesn't exist.
  • 400: a field is longer than 500 characters, or there are more than 30.
  • 422: an image link was refused; the response says why.
  • 429: too many requests from one address in a minute.
Cardboard docs