OpenGraph images are the preview images that appear when you share a link on social media. One supports dynamic OG image generation using API routes and the @vercel/og library.
Install the @vercel/og package:
yarn
npm
bun
pnpm
Create an API route that generates images dynamically:
app/api/og+api.tsx
This creates an endpoint at /api/og that generates PNG images on the fly.
Reference the dynamic image in your page’s meta tags:
app/blog/[slug].tsx
Load custom fonts for better typography:
app/api/og+api.tsx
Include images in your OG graphics:
app/api/og+api.tsx
Create a utility to generate OG URLs consistently:
features/og.ts
Use it in pages:
Add cache headers for better performance:
app/api/og+api.tsx
Test your OG images directly in the browser:
Terminal
Use the OpenGraph debugger or social platform preview tools to verify how images appear when shared.
Edit this page on GitHub.