Image workflow

Every image generated by Meridian flows through a hardened pipeline: DALL·E 3 creation, automated moderation, persistent storage, and CDN delivery — all before a single pixel reaches the user.

Step 1

DALL·E 3 generation

When a user submits a prompt, Meridian forwards it to OpenAI's DALL·E 3 API with quality=hd, size=1024x1024, and style=vivid. The raw base64 response is held in memory — never written to disk in plain form.

const image = await openai.images.generate({
  model: "dall-e-3",
  prompt: sanitizedPrompt,
  n: 1,
  size: "1024x1024",
  response_format: "b64_json",
});
Step 2

Moderation

Before storage, the image passes through OpenAI's moderation endpoint. If flagged, the image is discarded and the user receives a policy violation notice. Clean images proceed.

const mod = await openai.moderations.create({
  input: imageBase64,
});

if (mod.results[0].flagged) {
  throw new PolicyViolationError();
}
Step 3

Save

Approved images are decoded, compressed to WebP at quality 85, and uploaded to Vercel Blob with a content-addressed key. A database record links the key to the user and prompt.

const buffer = Buffer.from(b64, "base64");
const webp = await sharp(buffer)
  .webp({ quality: 85 })
  .toBuffer();

const { url } = await put(
  `images/${hash}.webp`,
  webp,
  { access: "public" }
);
Step 4

CDN delivery

Vercel Blob serves images through a global edge cache. The public URL is returned to the client and rendered immediately. Subsequent requests hit the CDN edge — zero origin latency.

// Response to client
return NextResponse.json({
  id: record.id,
  url: blobUrl, // https://<cdn>/images/<hash>.webp
  prompt: record.prompt,
  createdAt: record.createdAt,
});