Astro guide
OG Image Generator for Astro
Generate a signed OG image URL in Astro's server context and render it in the layout metadata. The JavaScript SDK reads OG_PILOT_API_KEY and OG_PILOT_DOMAIN, signs the payload, and returns a CDN URL. Put that URL in og:image and twitter:image. Keep the call on the server. A client island that can see the API key is the wrong place to create the image.
Static Astro builds can generate the URL at build time from frontmatter and the route. Server-rendered routes can generate it per request. Both are valid. The choice is whether the card should freeze when you build, or follow the page data on each request. Pass the template that matches the page: a generic page, a blog post, a product, an event, or another template from the API. Pass iat when you want the documented cache window to start at that timestamp. Omit it and the cache does not expire on its own.
Integration steps
- Set OG_PILOT_API_KEY and OG_PILOT_DOMAIN in the Astro server environment. Do not prefix the key in a way that exposes it to the browser.
- Create a helper that calls createImage with the title, description, path, and template.
- Await that helper in the layout and set the Open Graph and Twitter meta tags to the returned URL.
- Publish, then re-check the URL in the Open Graph debugger so you see what crawlers will cache.
Different routes can use different templates. A blog entry and a marketing page should not share one generic card if you have titles, dates, or images to show. The API docs list the fields and the signed POST to /api/v1/images. MCP covers the case where an agent creates or debugs the image from the page URL instead of the Astro build. Debug, compress, and palette work on a guest connector session. generate_og_image needs an account with an active plan.
Neighboring guides
Rails apps should follow the Rails OG image guide and the og_pilot_ruby gem. Next.js apps comparing opengraph-image files, ImageResponse, and a hosted API should read the Next.js guide. The longer comparison of hosted OG Pilot, @vercel/og, and DIY Satori is on the OG image API page. Astro is usually the hosted-API choice: the site is not an App Router project, and you still want a CDN URL in the layout rather than a Satori bundle inside the build. The three-way comparison of a public/ file, a build-time endpoint, and the on-demand API is Dynamic OG images for Astro.
If crawlers need to fetch the image, the URL has to be absolute https. A relative path can look fine in a browser and fail in a unfurl. After you change the artwork, change the URL or force a rescrape. Platforms cache the bytes, not your Astro source.