Skip to content

Cover Image Generation

API routeapp/api/generate-cover/route.ts
Image modelgemini-2.5-flash-image (via lib/gcp/imagen.ts)
Storage pathimages/{storyId}/cover.png
Triggered byGenerationProvider.tsx / useStoryAssembler.ts — after all page images finish

What it does

Generates a dedicated front cover illustration for the story — separate from the page images. The cover has a centered composition with space at the top for the title, watercolor children's book style, and no text on the image.


Prompt

Children's storybook front cover for a book titled "{title}".
Story theme: {firstPageImagePrompt}.
Beautiful illustrated cover art, colorful and magical, centered composition
with space at the top for a title, watercolor children's book style,
whimsical, soft warm colors, inviting and joyful, safe for children,
portrait orientation, no text on the image
  • title — AI-generated story title from StoryWriter
  • firstPageImagePrompt — used as a theme hint (optional — omitted if not available)
  • No referenceImages passed — the cover is a scene shot, not character-focused

Flow

All page images generated


POST /api/generate-cover { storyId, title, firstPageImagePrompt }


generateImage(coverPrompt, [])     ← no reference images


uploadAndSign(buffer, "images/{storyId}/cover.png", "image/png")


{ coverImageUrl }  → saved to Firestore story.coverImageUrl

Storage

images/{storyId}/cover.png

The coverImageUrl field on the Firestore story document points to this GCS signed URL. It is displayed in:

  • The dashboard library card thumbnail
  • The story header/cover page
  • The OG meta image for public story sharing (/s/[id])

Released under the MIT License.