March 28, 2026 · 6 min read

How to Generate Dynamic OG Images with an API

Open Graph images are the single biggest lever for improving click-through rates on social media. Yet most developers still create them manually in Figma or skip them entirely. Here's how to automate the entire process with a single API call.

The Problem with Manual OG Images

Every time you publish a blog post, launch a landing page, or create a product page, you need a social preview image. This is the card that appears when someone shares your URL on Twitter, LinkedIn, Slack, or Facebook.

The standard workflow looks like this:

  1. Open Figma or Canva
  2. Create a 1200×630 image with your title and branding
  3. Export as PNG
  4. Upload to your CMS or static assets
  5. Add the URL to your <meta> tags

For one page, that's fine. For a blog with 50+ posts, a docs site with hundreds of pages, or a SaaS with dynamic content—it's unsustainable.

The API Approach

Instead of creating images manually, you define them as parameters in a URL. The API generates the image on the fly and returns a PNG.

Here's what that looks like with OGPeek:

<meta property="og:image"
  content="https://ogpeek.com/api/v1/og
    ?title=How+to+Generate+Dynamic+OG+Images
    &subtitle=The+2026+Developer+Guide
    &template=gradient
    &theme=midnight
    &brandColor=%23FF7A00" />

That single line generates this image:

Example OG image generated by OGPeek

No Figma. No manual export. No upload step. The image is generated when the social platform requests it.

How OG Image Generation Works

Under the hood, modern OG image APIs use SVG-native rendering instead of headless browsers. Here's why that matters:

OGPeek uses the SVG-native approach. Your request hits the API, Satori generates SVG from the template + parameters, resvg converts it to a 1200×630 PNG, and you get the image back in under 200ms.

Step-by-Step Integration

1. Choose Your Template

OGPeek ships with four templates designed for different use cases:

2. Pick a Theme and Brand Color

Each template supports five built-in themes (dark, light, midnight, forest, sunset) and a custom brandColor parameter for exact brand matching.

3. Add to Your HTML

The simplest integration is a direct URL in your meta tags:

<meta property="og:image"
  content="https://ogpeek.com/api/v1/og?title=YOUR_TITLE&template=gradient&theme=dark" />
<meta property="og:image:width" content="1200" />
<meta property="og:image:height" content="630" />

4. Dynamic Titles (Server-Side)

For blogs and dynamic pages, inject the title server-side:

// Next.js example
export async function generateMetadata({ params }) {
  const post = await getPost(params.slug);
  return {
    openGraph: {
      images: [`https://ogpeek.com/api/v1/og?title=${
        encodeURIComponent(post.title)
      }&template=gradient&theme=midnight`],
    },
  };
}

5. Use POST for Paid Features

The free GET endpoint adds a small watermark. For watermark-free images at higher volume, use the POST endpoint with an API key:

curl -X POST "https://ogpeek.com/api/v1/og" \
  -H "x-api-key: ogp_your_key_here" \
  -H "Content-Type: application/json" \
  -d '{"title":"My Post","template":"gradient","theme":"midnight"}' \
  --output og.png

Pro tip: Set your brandColor to match your site's primary color. This creates visual consistency between your social cards and your actual site, which builds recognition in feeds.

When to Use an OG Image API

An API approach makes sense when:

If you have a single landing page, manual design is fine. For everything else, automate it.

OGPeek vs. Alternatives

Here's how OGPeek compares to other options in the market:

Try it now

Generate your first OG image in under a minute. No signup required for the free tier.

Open the playground →

Conclusion

Dynamic OG image generation removes one of the most tedious parts of shipping content. Instead of context-switching to a design tool for every page, you define your social preview as code and let the API handle rendering.

The result: consistent, branded social cards across your entire site, generated on demand, for a fraction of the cost of enterprise tools.

More developer APIs from the Peek Suite