{"id":311,"date":"2026-10-15T21:33:08","date_gmt":"2026-10-15T21:33:08","guid":{"rendered":"https:\/\/blog.skndan.com\/jsontoimg\/2026\/10\/15\/nextjs-og-image-vs-template-api\/"},"modified":"2026-11-17T13:33:29","modified_gmt":"2026-11-17T13:33:29","slug":"nextjs-og-image-vs-template-api","status":"publish","type":"post","link":"https:\/\/blog.skndan.com\/jsontoimg\/2026\/10\/15\/nextjs-og-image-vs-template-api\/","title":{"rendered":"Next.js OG Image: @vercel\/og ImageResponse vs a Template API"},"content":{"rendered":"<p>A Next.js OG image has two good implementations, and they fail in different places. <code>ImageResponse<\/code> generates the image inside your app. A template API signs a URL and lets another service render it. Pick by who edits the layout and how complex it is, not by which demo looks nicer.<\/p>\n<h2>Option 1: <code>opengraph-image<\/code> and <code>ImageResponse<\/code><\/h2>\n<p>Next.js supports an <a href=\"https:\/\/nextjs.org\/docs\/app\/api-reference\/file-conventions\/metadata\/opengraph-image\"><code>opengraph-image<\/code> file convention<\/a> and the <a href=\"https:\/\/nextjs.org\/docs\/app\/api-reference\/functions\/image-response\"><code>ImageResponse<\/code><\/a> constructor, which turns JSX and CSS into a PNG at 1200 by 630 by default. It runs inside your deployment with no extra service.<\/p>\n<p>The documented limits matter: only flexbox and a subset of CSS properties work, <code>display: grid<\/code> will not, and the bundle, including fonts and images, is capped at 500KB. The layout lives in your repo, so a designer&#39;s change is an engineer&#39;s pull request.<\/p>\n<h2>Option 2: sign a URL from a template<\/h2>\n<pre><code>import type { Metadata } from &quot;next&quot;;\n\nexport async function generateMetadata({ params }): Promise&lt;Metadata&gt; {\n  const post = await getPost((await params).slug);\n  const { url } = await client.signImageUrl({\n    template: process.env.OG_TEMPLATE_ID!,\n    format: &quot;png&quot;,\n    layers: { headline: { text: post.title } },\n  });\n  return {\n    openGraph: { images: [{ url, width: 1200, height: 630, alt: post.title }] },\n  };\n}\n<\/code><\/pre>\n<p><a href=\"https:\/\/nextjs.org\/docs\/app\/api-reference\/functions\/generate-metadata\"><code>generateMetadata<\/code><\/a> renders the tag into the server HTML. The designer edits the template in the editor; your code only sends the title. The signed URL contains the pinned template <code>version<\/code>, so a design change never alters a card that is already live.<\/p>\n<h2>How to choose<\/h2>\n<table>\n<thead>\n<tr>\n<th>Question<\/th>\n<th>ImageResponse<\/th>\n<th>Template API<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Is the layout simple text on a gradient?<\/td>\n<td>Fits<\/td>\n<td>Fits<\/td>\n<\/tr>\n<tr>\n<td>Does it need grid, many fonts, or large images?<\/td>\n<td>Hits the documented limits<\/td>\n<td>Fits if the editor can draw it<\/td>\n<\/tr>\n<tr>\n<td>Does a designer edit it?<\/td>\n<td>Needs an engineer<\/td>\n<td>Edits in the editor<\/td>\n<\/tr>\n<tr>\n<td>Does it add a service dependency?<\/td>\n<td>No<\/td>\n<td>Yes<\/td>\n<\/tr>\n<tr>\n<td>Is cost per image zero?<\/td>\n<td>Compute only<\/td>\n<td>One credit per unique URL<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>The honest default<\/h2>\n<p>Start with <code>ImageResponse<\/code> if you have one layout, one engineer, and no designer in the loop. Move to a template when the second layout or the first design request arrives. The cutover is small: replace the <code>opengraph-image<\/code> file with the <code>generateMetadata<\/code> function above.<\/p>\n<p>Implementation detail and WordPress are in <a href=\"https:\/\/jsontoimg.com\/blog\/auto-generate-og-images-with-jsontoimg\">Sign Open Graph Image URLs in Next.js and WordPress<\/a>. The pipeline and debugging live in the <a href=\"https:\/\/jsontoimg.com\/blog\/open-graph-image-generator-guide\">Open Graph image generator guide<\/a>.<\/p>\n<h2>FAQ<\/h2>\n<h3>How do I generate a dynamic OG image in Next.js?<\/h3>\n<p>Use the opengraph-image file convention with ImageResponse to render JSX to a PNG in your app, or return a signed template-API URL from generateMetadata.<\/p>\n<h3>What are the limits of Next.js ImageResponse?<\/h3>\n<p>Next.js documents support for flexbox and a subset of CSS properties, no display: grid, and a 500KB bundle limit that includes fonts, images, and other assets.<\/p>\n<h3>Does jsontoimg replace ImageResponse?<\/h3>\n<p>It is an alternative. ImageResponse keeps the layout in code with no extra service. jsontoimg moves the layout into an editor so a designer can change it without a deploy.<\/p>\n<h3>What does a template API cost per OG image?<\/h3>\n<p>One credit for the first unique URL fetched, and zero for repeat fetches of the same title. Minting the signed URL is free.<\/p>\n<h2>Related Resources<\/h2>\n<ul>\n<li><a href=\"https:\/\/jsontoimg.com\/blog\/og-image-not-showing-debug-checklist\">OG image not showing? Debug checklist<\/a><\/li>\n<li><a href=\"https:\/\/jsontoimg.com\/tools\/free-open-graph-image-generator\">Free OG image generator<\/a><\/li>\n<li><a href=\"https:\/\/jsontoimg.com\/blog\/json-to-image-converter\">How JSON-to-image conversion works<\/a> \u2014 the pillar guide<\/li>\n<li><a href=\"https:\/\/jsontoimg.com\/blog\/open-graph-image-generator-guide\">Open Graph image generator guide<\/a> \u2014 the full flow<\/li>\n<li><a href=\"https:\/\/jsontoimg.com\/blog\/html-to-image-api-vs-template-api\">HTML to image API vs template API<\/a> \u2014 the general trade-off<\/li>\n<li><a href=\"https:\/\/jsontoimg.com\/use-cases\/open-graph-images\">Open Graph images use case<\/a> \u2014 signed OG URLs<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>When to build a Next.js OG image with ImageResponse and when to sign one from a template API, with the limits Next.js documents and the code for both.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-311","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blog.skndan.com\/jsontoimg\/wp-json\/wp\/v2\/posts\/311","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.skndan.com\/jsontoimg\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.skndan.com\/jsontoimg\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.skndan.com\/jsontoimg\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.skndan.com\/jsontoimg\/wp-json\/wp\/v2\/comments?post=311"}],"version-history":[{"count":1,"href":"https:\/\/blog.skndan.com\/jsontoimg\/wp-json\/wp\/v2\/posts\/311\/revisions"}],"predecessor-version":[{"id":375,"href":"https:\/\/blog.skndan.com\/jsontoimg\/wp-json\/wp\/v2\/posts\/311\/revisions\/375"}],"wp:attachment":[{"href":"https:\/\/blog.skndan.com\/jsontoimg\/wp-json\/wp\/v2\/media?parent=311"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.skndan.com\/jsontoimg\/wp-json\/wp\/v2\/categories?post=311"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.skndan.com\/jsontoimg\/wp-json\/wp\/v2\/tags?post=311"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}