Vercel AI SDK
The AI SDK's generateImage gives you the image's bytes; one more call marks them for the EU AI Act and California. It works with any image model the SDK reaches, through the AI Gateway or a provider package.
In short
- Step: after
generateImage, pass each image tomark(), then use only what it returns. - Helper: the one from the Next.js guide, in
lib/kennmarq.ts. - Models: any, including FLUX, GPT Image, Imagen and Recraft; credentials a provider already added are kept.
- Written for: AI SDK 7 (the ai package), checked on 24 October 2026.
Generate, then mark
app/api/image/route.ts
// app/api/image/route.ts
import { generateImage } from "ai";
import { mark } from "@/lib/kennmarq"; // the helper from the Next.js guide
export const maxDuration = 60;
export async function POST(request: Request) {
const { prompt } = await request.json();
const { image } = await generateImage({ model: "bfl/flux-3-image", prompt });
const file = new Blob([image.uint8Array], { type: image.mediaType });
const marked = await mark(file, `image.${image.mediaType.split("/")[1]}`, { model: "FLUX.3" });
// Only the marked copy leaves this route. If mark() threw, the request fails instead.
return new Response(marked, { headers: { "Content-Type": image.mediaType } });
}The same two lines work in a server action, or wherever your server calls generateImage. The model here comes from the AI Gateway; with a provider package, pass its model instead.
Several images at once
TypeScript
const { images } = await generateImage({ model: "bfl/flux-3-image", prompt, n: 4 });
// One call each. One after another keeps a Free plan (10 calls a minute) well within its limit.
const marked: Blob[] = [];
for (const image of images) {
marked.push(await mark(new Blob([image.uint8Array], { type: image.mediaType }), "image.png"));
}Images that already carry credentials
Some providers sign their images with Content Credentials of their own. We keep those as an ingredient of ours, as the EU's Code of Practice asks, and add your company and app, the watermark and California's five items on top.
Next
- Videos and audio go through the same helper: see videos.
- What each mark carries: Content Credentials and invisible watermarks.
- Let your coding agent do it: the prompt.