Notice: Black Friday 2026 × Cyber Monday: Get up to 30% extra on top-ups, DeepSeek free to use · View the promotion
Blog

Tutorial

Hands-on text-to-image with mai-image-2.7: 5 high-value business scenarios and implementation essentials

From e-commerce assets to batch content production: implementing 5 types of real needs with a unified image generation API

Nov 27, 2026
On a dark blue background, five parallel copper-colored wiring texture areas with a gradually varying density, in a vintage technical print style cover image
On this page

Why choose a text-to-image API instead of building it in-house

Before deciding to put text-to-image capabilities into your product, answer one question: should this really be built in-house, or should it go through a unified API? The answer depends on three dimensions — cost structure, iteration pace, and maintenance burden.

Building image generation in-house means preparing an inference environment, maintaining model versions, handling concurrency scaling and GPU memory scheduling, and continuously keeping up with quality iterations. For teams where image generation is only a supporting product capability, this infrastructure investment is hard to amortize across business volume. The real cost is not a one-time deployment, but long-term maintainability.

A unified API is much simpler to call. Take mai-image-2.7/text-to-image for example: the output type is image, the capability is pure text-to-image, billing is per image, and on the engineering side you only need one HTTP call plus a place to store results. You can focus your effort on prompt design and business integration instead of model operations.

The criteria come down to a few points: Is image generation your core competitiveness? Is the daily call volume large enough to amortize in-house costs? Does the team have the manpower to continuously follow model iterations? If most answers are "no", you should start with the API. Conversely, only when generation quality, private-data training, or extreme latency become hard barriers is in-house building worth considering. For the vast majority of business scenarios, using a unified interface to get the workflow running and to accumulate prompts is the most cost-effective path.

Etched copper-colored line-art decision tree: the short branches on the left converge into a thick, dense parallel block, while the long branches on the right feed into a single light, thin loop channel, with dense hatching growing sparser from left to right.
From the same decision origin, two paths diverge: on the left, the dense stacking and maintenance burden of in-house building; on the right, the lightweight convergence channel of an aggregated API.

Scenario 1: E-commerce and product hero image assets

E-commerce is the most typical text-to-image scenario: a product needs a hero image, scene image, mood image, and detail supplement images. The traditional approach relies on a photo studio and post-production, with long cycles and high costs. Text-to-image can quickly produce "the scene the product sits in".

The key is prompt templating. Do not write prompts from scratch every time; instead, break product attributes into fixed slots:

Subject: {product name}, {material}, {color}
Scene: {usage scenario}
Lighting: soft light/natural light/studio strobe
Composition: centered/rule of thirds/top-down
Style: commercial photography/minimalist/lifestyle
Aspect ratio: 1:1

The benefit of fixed slots is reproducible style. For the same batch of products, you only replace the subject field while keeping scene, lighting, and composition consistent, so the produced hero images share a unified visual language and do not look cluttered on a listing page.

On the engineering side, turn this template into a configurable struct, and assemble it into the final prompt when calling mai-image-2.7/text-to-image. Note that product descriptions must be specific; avoid vague expressions like "nice clothes", because the model cannot extract effective visual information from them. It is recommended to store generated results in a database or storage archive; the same product with the same template combination can be reused without being billed again.

Copper-colored engraving-style flowchart: a product block passes through nested template frames into six small samples, which then converge into a product listing grid on the right.
From a product brief fixed into a prompt template, assets in the same style are batch-generated and merged into the listing page.

Scenario 2: Marketing campaigns and banner imagery

Campaign pages are characterized by short timelines, multiple sizes, and multiple styles. One campaign concept needs to be used in the hero banner, sidebar, pop-up, mobile, and other places, each with different sizes and ratios.

The strategy is "one concept, multiple variants". First generate a baseline image with a complete prompt to confirm the visual direction; then adjust aspect ratio and element density around the same concept to generate variants for each size. Explicitly specify aspect ratio and compositional focus in the prompt, such as "leave space on the left for copy" and "safe area for top and bottom cropping", to avoid placing key elements at the crop edges.

How batch tasks are organized matters a lot. Treat each "concept × size × style" combination as one task unit, put it in a queue, and record the task ID and prompt. After the campaign ends, the mapping between this set of prompts and the outputs becomes reference assets for the next campaign. Campaign cycles are short and manpower is tight, so preparing prompt templates and batch scripts in advance is far more efficient than hastily generating images one by one at the last minute.

On a dark blue background, a densely hatched node branches out to the right into thin copper-colored lines connecting banner rectangles of various sizes and hatching densities arranged in a grid.
One campaign concept branches along prompts to batch-generate banner variants of different sizes and styles.

Scenario 3: Hero image generation for blogs and content platforms

The most common pain point for content teams: the article is finished, but the hero image is still missing. Automatically turning titles into accompanying images can significantly speed up publishing cadence.

The approach is to establish rules for converting titles into prompts. Do not throw the title at the model as-is; instead extract the topic, domain, and emotion, then assemble them into a visual description. For example, for an article about "distributed caching", the converted prompt should describe concrete visual elements and style rather than piling up abstract terminology.

A typical pipeline integrated into publishing is: article finalized → extract title and summary → assemble prompt → call the API to generate → store in object storage → write the cover URL back to the content system. This pipeline is suitable as an asynchronous task: generation failure does not block publishing, and it can fall back to a default cover. For style, it is recommended to unify a platform visual guideline (for example, a fixed color palette and compositional tendency) so that all hero images look like they belong to the same content brand.

Scenario 4: In-app placeholder images and personalized visuals

Empty states, loading placeholders, card backgrounds — these places used to be filled with static assets or solid colors, giving a bland experience. Text-to-image can dynamically generate visuals that fit the context and scenario.

But boundaries must be drawn here. Dynamic generation is suitable for low-frequency, non-critical-path positions: ambient backgrounds on a user profile page, guide illustrations when a certain type of data is empty, periodic image rotation in operational slots. It is not suitable for elements that appear frequently at key positions in the main flow — there, call volume and latency are both uncontrollable.

A feasible approach is pre-generation plus caching. Enumerate a limited set of combinations by theme, color tone, and scenario, batch-generate a small set of candidate images in advance, and select at runtime based on user attributes or context instead of making a real-time request every time. This gives the feel of "personalization" while keeping call volume within budget. Personalization dimensions should be limited to a small number of attributes (such as theme color, industry category); the more dimensions, the worse the combinatorial explosion.

Scenario 5: Creative exploration and prompt iteration

Before formal batch production, the prompts themselves need exploration. The cost of a single call is low, which makes it ideal for A/B iteration.

The method is controlled variables: change only one factor at a time (lighting, style, composition), generate samples and review them manually, record which version better matches the goal, then proceed to the next round. Turn each validated prompt into a structured entry — scenario, full prompt text, parameters, review conclusion — forming a prompt library shared by the team.

The value of this library accumulates over time: new projects do not have to start trial and error from scratch; they can directly reuse validated combinations and only fine-tune the differences. In the exploration phase, do not chase perfection in one shot; instead, make "trial — record — converge" a fixed process. Note that every generation is billed per image, so exploration must also be restrained: first validate direction with low resolution and small batches, then scale up after confirmation.

Engineering implementation and cost control for batch generation

The engineering essentials for batch scenarios focus on four points: concurrency, retries, deduplication, and budget.

  • Concurrency: Use a queue to control the concurrency level, avoiding instant exhaustion of quotas and making it easier to reschedule failed tasks.
  • Retries: Distinguish retryable errors (timeouts, rate limiting) from non-retryable errors (prompt policy violations). Retrying the latter is meaningless; mark them as failed directly and record the reason.
  • Deduplication: Hash "prompt + parameters" and reuse existing results directly on a cache hit without calling again. This is the most direct cost-saving measure.
  • Budget: Billing is per image, and the unit price can be found on the site's pricing panel. Estimate batch budget as "planned image count × unit price", and maintain a counter of generated images in the task queue, alerting when approaching the threshold.

When storing results, record the prompt, parameters, task status, and output address, which facilitates auditing and provides a basis for later reuse. Batch tasks should be designed to be idempotent, so that resubmitting the same batch does not cause duplicate billing. For specific API parameters and invocation methods, refer to the mai-image-2.7/text-to-image model page.

Common issues and troubleshooting checklist

When encountering problems, troubleshoot in the following order:

  1. Request rejected: First check whether the prompt violates the content policy; remove sensitive or vague descriptions and retry; confirm that the parameter format matches the API requirements.
  2. Style drift: Check whether the prompt differs slightly each time, or whether missing scene/lighting fields cause the model to improvise. Fixed template slots significantly improve consistency.
  3. Uncontrollable output: When element positions or counts do not match expectations, replace abstract adjectives with more explicit composition and spatial descriptions, and reduce the target complexity of a single generation.
  4. Duplicate results: Confirm whether the deduplication hash is working, and whether the prompt and parameters are really identical.
  5. High failure rate: Break down statistics by error type; if it is rate limiting, reduce concurrency; if it is a prompt problem, go back to the template layer to fix it.

Write each troubleshooting conclusion back into the prompt library and task logs, so the same type of problem does not have to be solved again next time. Stability comes from standards, not luck.

Related articles

View all articles →

Start building with persistent AI artifacts

Get your API key and call image, video and audio models through one task-based API.

Read the API docs