Skip to content
AI-powered appsNewChat, vision, voice, generationBookings & schedulingAppointments that book themselvesShops & sellingA storefront in every pocketClient & businessRun the operation from one placeCommunities & clubsA home that is not a group chat
Health & wellnessHabits, tracking and calmGames2D, 3D and multiplayerPersonal & toolsThe tool you wish existedInternal toolsThe tool ops never had time for
See all use cases
ArcadeNewPricingSecurity
EngineThe game engine and World EditorHow it worksFrom one sentence to a live productDocsGuides for building and publishingBlogStories, guides and newsChangelogWhat shipped latelyStatusUptime of every serviceSupportGet help from the team
AI-powered appsBookings & schedulingShops & sellingClient & businessCommunities & clubsHealth & wellnessGamesPersonal & toolsInternal tools
See all use cases
ArcadeNewPricingSecurity
EngineHow it worksDocsBlogChangelogStatusSupport
Language
Blog
GuidesNovember 22, 20266 min read

How to Build an AI Image Generator App

Every image costs you money, so an image generator is really a credit system with a queue attached. Build the ledger first, then the fun part.

Startbase Team
Editorial ink illustration of a darkroom enlarger over a tray of developing paper, the enlarger bulb in ember orange

Key takeaways

  • Win with a narrow use case (pet portraits, product backdrops, tattoo sketches) and a preset style, not a blank prompt box.
  • Use a credit ledger: one row per grant, purchase and spend. Deduct before generating and refund on failure.
  • Treat each generation as a job with a status, so slow requests, failures and retries are visible and safe.

An AI image generator app needs a way to take a request (a prompt, often a style and sometimes an uploaded photo), a server-side call to an image model, a queue that tracks each generation from pending to done or failed, storage and a gallery for results, and a credit system so every image is paid for. The model call is the easy part. Credits, the queue and moderation are what turn a demo into an app you can open to strangers without losing money or sleep.

A focused app beats a prompt box

A blank "describe anything" box competes with every general image tool. A focused app does one job with a curated result: pet portraits in five painting styles, product photos on clean studio backgrounds, children's book illustrations of the same character, tattoo flash sketches, interior moodboards, birthday card fronts. Focus lets you write the prompt yourself and hide it behind simple choices, which produces far more consistent results than users' own prompts, and it gives you a clear audience to market to.

In practice, the user picks a style card and types a few words or uploads a photo, and your server builds the real prompt from a template: the style's description, the subject, composition rules and things to avoid.

The data model

  • styles: name, preview image, the prompt template, default size or aspect ratio, credit cost, and an active flag.
  • generations: user id, style id, the user's input text, the full prompt actually sent, an input image path if any, status (queued, running, succeeded, failed, blocked), error message, result image paths, credits charged, created and finished times.
  • credit_ledger: user id, amount (positive for grants and purchases, negative for spends and refunds as positive again), reason (signup bonus, purchase, generation, refund), a reference to the generation or order, and created date. The balance is the sum.
  • orders: user id, credit pack, amount paid, Stripe session id, status.
  • favorites and public_gallery (optional): which images a user saved or chose to share.

A ledger instead of a single balance column sounds fussy and saves you every time something goes wrong. When a user writes "I paid and got no credits" or "it charged me for a failed image", the ledger tells you exactly what happened.

Credits that never go negative

  1. 01User clicks Generate. A server function checks the balance and, in the same transaction, inserts a spend row and a queued generation. If the balance is too low, it returns "not enough credits" with a link to buy more.
  2. 02The function calls the image model.
  3. 03On success, it saves the image to storage and marks the generation succeeded.
  4. 04On failure (an error, a timeout, or the provider's own safety refusal), it marks it failed and inserts a refund row.

Credit packs are sold with a Stripe checkout, and only the Stripe webhook adds purchase rows. Give a few free credits on sign-up so people see a result before paying, and limit free credits to verified emails, or new accounts become a free image farm.

On Startbase, your app can call image generation through the App AI gateway's generateImage helper without its own API keys. Know how it is billed: generated images use your Build credits, the same balance you build with, so your credit prices to users need to cover what each image costs you. Project and organization rate limits apply to gateway requests. Details are in the AI docs.

The queue: statuses, waiting and retries

Image generation can take several seconds or longer. Never make the user stare at a frozen button:

  • Show the generation card immediately in the gallery with a "creating" state and the style preview blurred behind it.
  • Update it when the status changes, either by listening for changes to the user's generations or by polling every couple of seconds.
  • Allow a small number of running generations per user (two or three) and queue the rest, which also protects your rate limits.
  • A scheduled job can mark generations stuck in running for more than a few minutes as failed and refund them, so a lost request never eats credits.

Storage and the gallery

Save every result to your own storage right away instead of linking to the provider's temporary URL, which may expire. Store images in a private bucket by default and show them through signed links (Startbase Cloud generates links that are valid for an hour), and move an image to a public gallery only when its owner chooses to share it. Make thumbnails for the gallery grid; full-size images are for the detail view and downloads. See Storage.

Moderation you cannot skip

Open an image generator to the public and someone will try to make something you do not want your name on within hours. Layers that work together:

  • Your prompt template constrains output to your use case. A pet portrait app has little reason to accept arbitrary subjects.
  • Input screening: check the user's text before generating. A quick text classification call with a schema (allowed, blocked, reason) catches most attempts; block a short list of terms outright.
  • Uploaded photos of real people: be clear in your terms that users may upload only photos they have the right to use, and refuse requests to place real, named people into sexual, violent or deceptive scenes.
  • The provider's own safety system refuses some requests; show a friendly message and refund.
  • Reporting on any publicly shared image, and an admin view of recent generations and blocked prompts.

Tip

Log the full prompt you sent, not just what the user typed. When a strange image appears, you need to know whether the template or the input caused it.

The screens

  1. 01Create: style cards, a short input field or photo upload, the credit cost on the button.
  2. 02Gallery: the user's generations, newest first, with status, favorite, download and share.
  3. 03Image detail: full size, the style, regenerate with the same settings, delete.
  4. 04Credits: balance, packs to buy, and the history from the ledger.
  5. 05Admin: styles editor with prompt templates, recent generations, blocked prompts, reports.

What to leave out of version one

  • Free-form prompts for everyone. Offer an advanced box later to paying users if they ask.
  • Video generation, upscaling chains and inpainting editors.
  • Subscriptions. Credit packs are easier to price while you learn real costs per image.
  • A public community feed. Moderating a feed is a job in itself.

A brief you can paste

Build a pet portrait app. Users sign in with email and get 5 free credits after confirming their email. They upload a photo of their pet, pick one of six styles (Renaissance oil, watercolor, studio photo, pop art, storybook, line drawing), and click Generate (1 credit). The server builds the prompt from the style's template plus a short description of the pet, checks the user's text input with an AI classification (allowed or blocked), deducts the credit and creates a queued generation in one transaction, calls image generation, saves the result to a private bucket with a thumbnail, and marks it succeeded; on any failure it marks it failed and refunds. A job every 5 minutes fails and refunds generations stuck running over 3 minutes. Max 2 running per user. Gallery updates live as statuses change. Credits come from a ledger table; packs of 20 and 60 are sold through Stripe and added only by the webhook. Images are private unless the owner shares a public link. Admin page with style templates, recent generations and blocked prompts.

Before opening it up, generate twenty images in each style and check them yourself; consistency is the product. To price your credit packs against your own costs, start from the credits on your Startbase plan, and the AI use case has more examples of apps built around models. For budget ranges, see what an AI app costs, and accepting payments in your app explains how credit pack purchases reach your account.

Frequently asked questions

How do AI image generator apps charge users?

Most sell credits in packs or include a monthly credit allowance in a subscription. Each generation spends credits, and failed generations should be refunded automatically.

How do I stop people making harmful images with my app?

Constrain prompts with your own templates, screen user input before generating, set clear rules for uploaded photos of real people, rely on the provider's safety refusals as another layer, and give users a way to report shared images.

Where should generated images be stored?

In your own storage, saved immediately after generation, since provider links can expire. Keep them private by default with signed links, and make thumbnails for galleries.

Why do image generations need a queue?

Generations take seconds and sometimes fail. A queue with statuses lets you show progress, limit how many run per user, retry or refund failures, and catch requests that never finish.

On this page

  • A focused app beats a prompt box
  • The data model
  • Credits that never go negative
  • The queue: statuses, waiting and retries
  • Storage and the gallery
  • Moderation you cannot skip
  • The screens
  • What to leave out of version one
  • A brief you can paste

Keep reading

More in Guides
Editorial ink illustration of a kitchen scale with an apple on its pan beside a notepad and a spoon, the apple in ember orange
GuidesNovember 22, 2026

How to Build a Calorie Tracker App

Calorie tracking fails when logging is slow or the numbers are wrong. Get reliable food data, make repeat meals one tap, and be honest that every number is an estimate.

6 min read
Editorial ink illustration of two tin-can telephones joined by a string across a garden fence, the knot in the string in ember orange
GuidesNovember 22, 2026

How to Build a Chat App

Chat looks simple and hides four hard problems: delivering messages live, knowing who is online, tracking who has read what, and keeping strangers from abusing it.

6 min read

Read less. Ship more.

Everything in this post is one prompt away. Describe your app and watch it build.

Start building

Apps, games, backends and publishing from one conversation.

Product

  • Features
  • Use cases
  • Pricing
  • Changelog

Resources

  • Blog
  • Docs
  • Support
  • Status
  • Security

Contact

  • w@startbase.ai
  • X / Twitter
  • LinkedIn
  • Instagram

Legal

  • Terms
  • Privacy

© 2026 Startbase. All rights reserved.