Skip to main content
Important: Add OGify packages to serverExternalPackages in your next.config.js:
This prevents Next.js from bundling OGify packages, which is necessary for proper font loading and image generation.
Next.js App Router provides two distinct ways to generate Open Graph images: using File Conventions (opengraph-image.ts) or using Route Handlers. Next.js has built-in support for generating images using opengraph-image.ts. This maps directly to OGify’s renderer.
1

Create opengraph-image.ts

Place this file in any route segment (e.g., app/opengraph-image.ts or app/posts/[slug]/opengraph-image.ts).
While Next.js provides ImageResponse, OGify returns a standard Buffer, which you can simply return in a standard Response object.

Option 2: Route Handlers

If you need a dynamic endpoint (e.g., /api/og?title=...) that enables you to generate images on demand for various pages, use a Route Handler.
1

Create the Route Handler

Create app/api/og/route.ts:
2

Use in Metadata