OG Image Generator API — dynamic previews for any page

Stop hand-crafting Open Graph images. Render an HTML template for each blog post, product page, or SaaS dashboard, then let aiSnapApi screenshot it at exactly 1200×630 — fast, cacheable, and on-brand.

100 free OG images/month · Cache at your CDN, burn 1 quota per unique image

The pattern

  1. Build an HTML template at https://yourdomain.com/og/<slug> that renders a 1200×630 OG card for any post.
  2. Hit aiSnapApi with that URL and width=1200&height=630.
  3. Cache the result at your CDN with a long Cache-Control.
  4. Set <meta property="og:image"> on your post page to your cached URL.

One screenshot per unique post. Twitter, LinkedIn, Slack, Discord all hit your CDN — not the API.

Next.js App Router: /api/og

// app/api/og/route.ts export async function GET(req: Request) { const { searchParams } = new URL(req.url); const slug = searchParams.get('slug'); const target = `https://yourdomain.com/og-template/${slug}`; const r = await fetch( `https://api.aisnapapi.com/v1/screenshot?url=${encodeURIComponent(target)}&width=1200&height=630`, { headers: { Authorization: `Bearer ${process.env.SNAPAPI_KEY!}` } } ); return new Response(r.body, { headers: { 'Content-Type': 'image/png', // Cache at the CDN for 1 year — change the slug to bust 'Cache-Control': 'public, max-age=31536000, immutable' } }); }

Then in your post page:

<meta property="og:image" content="https://yourdomain.com/api/og?slug=my-post" /> <meta name="twitter:card" content="summary_large_image" />

Why screenshot-based OG, not @vercel/og?

Common pitfalls

Start generating OG images — free

100 free screenshots every month. With CDN caching, that's hundreds of blog posts.

Get My Free API Key