This guide uses Minikit but the principles apply to any framework with server-side rendering.
Implementation
This guide shows how to create shareable links with dynamic embed images. Users click a share button, which opens a compose window with their personalized link. When shared, the embed displays a unique image with their username.1
Install the required package
Install
@vercel/og by running the following command inside your project directory. This isn’t required for Next.js App Router projects, as the package is already included:2
Create the image generation API endpoint
Build an API route that generates images based on the username parameter.This endpoint generates a unique image for each username:
app/api/og/[username]/route.tsx
/api/og/alice, /api/og/bob, etc.<div> elements must have display: "flex" or display: "none". If you see a 500 error when accessing /share/[username], check your ImageResponse JSX structure.3
Create shareable page with dynamic metadata
Build a page route that uses the username to generate When someone visits
fc:miniapp metadata pointing to your image endpoint.app/share/[username]/page.tsx
/share/alice, the metadata points to /api/og/alice for the embed image.4
Add share button with composeCast
Create a button that opens Farcaster’s compose window with the user’s personalized share link.When you click the button, it opens the compose window with
app/page.tsx
/share/alice as the embed. The embed displays the dynamic image from /api/og/alice.5
Test the flow
Verify the complete sharing flow works.Click the share button in your app to test the full experience. You should see the compose window open with your personalized share link, and the embed should display your custom generated image.
