# How to generate dynamic OG images in Nuxt

Source: https://snapsbrew.com/guides/nuxt-og-images

In Nuxt, sign a Snapsbrew image URL in a server route and set it with useSeoMeta. The signing key stays in the private runtime config, so the browser never sees it. The server route takes the slug of a page, not free text, so nobody can use it to render other images.

By [Alejandro Medina](https://amedina.me), maintainer of Snapsbrew. Published 27 November 2026. Last updated 27 November 2026.

On this page

- [What you need](#what-you-need)
- [Step 1: Add the private runtime config](#step-1-add-the-private-runtime-config)
- [Step 2: Install the SDK](#step-2-install-the-sdk)
- [Step 3: Sign the URL in a server route](#step-3-sign-the-url-in-a-server-route)
- [Step 4: Set the meta tags in the page](#step-4-set-the-meta-tags-in-the-page)
- [Step 5: Test it](#step-5-test-it)
- [A prerendered site](#a-prerendered-site)
- [When the design changes](#when-the-design-changes)
- [Other frameworks](#other-frameworks)

This guide gives each page of a Nuxt 3 or Nuxt 4 site its own `og:image`. A Snapsbrew template makes the image. Your Nuxt server only signs a URL. The first crawler that opens the URL makes the instance render the image, and later requests get the stored file.

The Nuxt part has one trap. Code in a page component runs on the server and also in the browser. A secret in that code ends up in the browser bundle. So the signing happens in a server route, and the page reads the finished URL.

## What you need

- A Snapsbrew instance that the public internet can reach. Read [Install with Docker](https://snapsbrew.com/docs/getting-started/installation-docker.md).
- A published template with the `open_graph` size preset (1200x630) and two text layers: `title` and `subtitle`. The [Next.js guide](https://snapsbrew.com/guides/nextjs-og-images.md#step-1-design-the-template) shows the steps.
- A signed-URL key from **Account > Developers > Signed URL API keys**.

## Step 1: Add the private runtime config

Keys at the top level of `runtimeConfig` are private. Only server code can read them. Keys under `public` go to the browser.

```ts
// nuxt.config.ts
export default defineNuxtConfig({
  runtimeConfig: {
    snapsbrewUrl: '',
    snapsbrewSigningKey: '',
    snapsbrewOgTemplate: '',
  },
})

```

Set the values with environment variables. Nuxt maps `NUXT_` plus the key in upper snake case to each key:

```
NUXT_SNAPSBREW_URL=https://snapsbrew.example
NUXT_SNAPSBREW_SIGNING_KEY=<signed-url-key>
NUXT_SNAPSBREW_OG_TEMPLATE=<template-uuid>

```

## Step 2: Install the SDK

The JavaScript SDK is on GitHub, not on npm yet. It has no runtime dependencies and runs on Node.js 20 or later, Bun, Deno and Cloudflare Workers, so it works with each Nitro preset.

```bash
npm install github:amedina068/snapsbrew-js

```

## Step 3: Sign the URL in a server route

The route takes a slug, finds the page, and returns the signed URL. It does not accept free text. If it did, anybody could call it to render any text on your instance.

```ts
// server/api/og/[slug].get.ts
import { signedUrl } from 'snapsbrew'
import { getPost } from '~~/server/utils/posts'

export default defineEventHandler(async (event) => {
  const slug = getRouterParam(event, 'slug')!
  const post = await getPost(slug)
  if (!post) throw createError({ statusCode: 404, statusMessage: 'No such post' })

  const config = useRuntimeConfig(event)
  const url = await signedUrl({
    baseUrl: config.snapsbrewUrl,
    key: config.snapsbrewSigningKey,
    templateId: config.snapsbrewOgTemplate,
    variants: [
      { layer: 'title', text: post.title },
      { layer: 'subtitle', text: `${post.author} · ${post.date}` },
    ],
  })

  return { url }
})

```

`getPost` is your own data function. It can read Nuxt Content, a CMS or a database.

## Step 4: Set the meta tags in the page

```
<!-- pages/blog/[slug].vue -->
<script setup lang="ts">
const route = useRoute()
const { data: post } = await useFetch(`/api/posts/${route.params.slug}`)
const { data: og } = await useFetch(`/api/og/${route.params.slug}`)

useSeoMeta({
  title: () => post.value?.title,
  ogTitle: () => post.value?.title,
  ogImage: () => og.value?.url,
  ogImageWidth: 1200,
  ogImageHeight: 630,
  twitterCard: 'summary_large_image',
  twitterImage: () => og.value?.url,
})
</script>

```

On the first server render, `useFetch` calls the route on the server. The result goes to the browser in the payload, so the browser does not call the route again for that page. The key never leaves the server.

## Step 5: Test it

Request the page and read the tag:

```bash
curl -s http://localhost:3000/blog/hello-world | grep -o '<meta property="og:image"[^>]*>'

```

Then request the image URL with `curl -sI`. A `302` with a `Location` header is a good render. A `200` with a small gray PNG is the placeholder: the key, the signature or the template ID is wrong. The [Next.js guide](https://snapsbrew.com/guides/nextjs-og-images.md#step-5-test-the-url) lists each response.

## A prerendered site

With `nuxt generate` or `routeRules` with `prerender: true`, the server route runs at build time. The signed URL is in the static HTML. This site, [snapsbrew.com](http://snapsbrew.com), is a prerendered Nuxt site.

The first request for each image still renders it on your instance. To render the images before anyone shares them, request each `og:image` URL one time after the deploy:

```bash
for page in $(grep -o '<loc>[^<]*' .output/public/sitemap.xml | cut -c6-); do
  img=$(curl -s "$page" | grep -o 'og:image" content="[^"]*' | cut -d'"' -f3 | sed 's/&amp;/\&/g')
  [ -n "$img" ] && curl -s -o /dev/null "$img"
done

```

## When the design changes

Edit the template in the editor and publish it. The publish changes the cache key of every signed URL of that template. The next request for each URL renders the new design. You do not deploy the Nuxt site again.

## Other frameworks

The method is the same in each framework: sign on the server, put the URL in the `og:image` tag.

- Next.js: [How to generate dynamic OG images in Next.js](https://snapsbrew.com/guides/nextjs-og-images.md)
- Laravel and Rails: [How to generate OG images in Laravel](https://snapsbrew.com/guides/laravel-og-images.md)
- Python: the Python SDK has `signed_url()`. Read [SDKs](https://snapsbrew.com/docs/sdks/overview.md).

## Questions

Why not sign the URL directly in useSeoMeta?

Code in a page runs on the server and also in the browser after a client-side navigation. If the page signs the URL, the signing key must be in the browser bundle. A server route keeps the key on the server.

Does this work with a fully prerendered Nuxt site?

Yes. During `nuxt generate`, `useFetch` calls the server route at build time. The signed URL goes into the HTML. The site needs no server after the build.

Can I use the nuxt-og-image module instead?

Yes. That module renders the image inside your Nuxt app. A signed URL moves the render to your Snapsbrew instance and lets a designer change the template with no deploy. Read [Dynamic OG images compared](https://snapsbrew.com/blog/dynamic-og-images-compared.md).

## Related pages

- [How to generate dynamic OG images in Next.js](https://snapsbrew.com/guides/nextjs-og-images.md)
- [How to generate OG images in Laravel](https://snapsbrew.com/guides/laravel-og-images.md)
- [Dynamic OG images compared: Satori, a headless browser or a template API](https://snapsbrew.com/blog/dynamic-og-images-compared.md)
- [Docs: Signed URLs](https://snapsbrew.com/docs/using-snapsbrew/signed-urls.md)

## Run it on your own server

Docker Compose starts the app, the queue, MySQL, Redis and the renderer together.

[Self-host it](https://snapsbrew.com/docs/getting-started/installation-docker.md) [View on GitHub](https://github.com/amedina068/snapsbrew)

```bash
git clone https://github.com/amedina068/snapsbrew.git
cd snapsbrew
cp .env.docker.example .env   # then fill in .env
docker compose up -d --build
```
