AI image generation: Where to Start?
In our projects, image generation models often produce unstable results: artifacts, divergence from the prompt, quality jumps when changing the seed. GPU inference costs grow non-linearly with load—without profiling, you might overpay for unused resources. Let's break down how to choose an architecture that balances quality, speed, and budget—from model selection to production deployment.
A typical case: an online store generates 10,000 product images per month—that's 3-4 designer man-months. AI reduces it to 2 hours of inference with p99 latency of 300 ms. The catch is that off-the-shelf models rarely fit perfectly: you need fine-tuning, pipeline integration, and cost control. Without customization, you either get an overpriced API or poor results.
Which Business Problems Does AI Image Generation Solve?
Generation of avatars, banners, article illustrations, product visualization, NFTs—all of this can be automated. Our clients use AI for content in e-commerce, marketing, and design. We eliminate bottlenecks: unstable results, high early-stage costs, and complex integration into existing pipelines. For example, for an online store with 50,000 generations per day, we deployed a cluster of 4 GPU A100s with a load balancer and Celery queue—p99 latency was 450 ms, and cost per image was $0.001. Savings on designers: approximately $8,000 per month. Our engineers have 5+ years of experience in Computer Vision and NLP, with 40+ completed AI generation projects.
AI Image Generation: Key Selection Parameters
| Model | Strengths | Cost per image | Controllability |
|---|---|---|---|
| DALL-E 3 | Text understanding, instruction following | $0.04 (API) | High |
| FLUX.1 Dev | Photorealism, detail | $0.002 (self-hosted) | High |
| SDXL | Flexibility, LoRA/ControlNet | $0.001 (self-hosted) | Maximum |
| Midjourney | Artistic style | $0.05 (subscription) | Low (no API) |
| Kandinsky 3 | Russian-language prompts | $0.001 (self-hosted) | Medium |
Model characteristics are based on official documentation.
FLUX.1 Dev provides detail comparable to Midjourney but with full API control. In our projects, we use it for e-commerce product image generation—speed is 2x higher than SDXL on the same hardware. At 5,000 generations per day, self-hosted FLUX pays for itself in 2-3 months (saving ~$5,000 monthly). Self-hosted FLUX is 5x cheaper than DALL-E 3 at volumes of 10,000+ generations per month.
How Do We Evaluate System Performance?
Key metrics: p99 latency (should be below 500 ms for interactive scenarios), throughput (up to 10 RPS per GPU A100), cost per image (low with self-hosting). During testing, we optimize batch size and steps—this cuts latency by 30-40% without quality loss. For ControlNet pipelines, we add profiling by FLOPS and GPU utilization to identify bottlenecks.
| Model | Typical latency (p99) | Optimal batch |
|---|---|---|
| DALL-E 3 | 2-5 sec | 1 |
| FLUX Dev | 1-3 sec on A100 | 4 |
| SDXL | 0.5-2 sec with optimization | 8 |
How to Choose a Model for Your Scenario?
- Define requirements: quality (photorealism, stylization), volume (RPS), budget (API vs self-hosted).
- Check compatibility: multilingual support, LoRA, ControlNet, inpainting.
- Compare latency from the table above.
- Account for customization: if branded styles are needed—train LoRA; if precise positioning is required—use ControlNet + Canny.
Integration and Deployment
Code example: DALL-E 3 via OpenAI API
from openai import AsyncOpenAI
import base64
client = AsyncOpenAI()
async def generate_image_dalle(
prompt: str,
size: str = "1024x1024", # 1024x1024, 1792x1024, 1024x1792
quality: str = "standard", # standard, hd
style: str = "vivid" # vivid, natural
) -> bytes:
response = await client.images.generate(
model="dall-e-3",
prompt=prompt,
size=size,
quality=quality,
style=style,
n=1,
response_format="b64_json"
)
return base64.b64decode(response.data[0].b64_json)
Code example: FLUX via Replicate API
import replicate
import httpx
async def generate_image_flux(
prompt: str,
aspect_ratio: str = "1:1",
num_outputs: int = 1
) -> list[bytes]:
output = await replicate.async_run(
"black-forest-labs/flux-dev",
input={
"prompt": prompt,
"aspect_ratio": aspect_ratio,
"num_outputs": num_outputs,
"guidance": 3.5,
"num_inference_steps": 28,
"output_format": "webp",
"output_quality": 90
}
)
images = []
async with httpx.AsyncClient() as http:
for url in output:
resp = await http.get(str(url))
images.append(resp.content)
return images
Code example: Self-hosted via ComfyUI (example client)
import websocket
import json
import uuid
class ComfyUIClient:
def __init__(self, server_address: str = "127.0.0.1:8188"):
self.server_address = server_address
self.client_id = str(uuid.uuid4())
def queue_prompt(self, workflow: dict) -> str:
import urllib.request
data = json.dumps({"prompt": workflow, "client_id": self.client_id}).encode("utf-8")
req = urllib.request.Request(f"http://{self.server_address}/prompt", data=data)
return json.loads(urllib.request.urlopen(req).read())["prompt_id"]
def get_image(self, filename: str, subfolder: str, folder_type: str) -> bytes:
import urllib.parse
data = urllib.parse.urlencode({"filename": filename, "subfolder": subfolder, "type": folder_type})
url = f"http://{self.server_address}/view?{data}"
return urllib.request.urlopen(url).read()
Code example: Queue Processing and Scaling
from celery import Celery
import redis
app = Celery("image_gen", broker="redis://localhost:6379/0")
@app.task(bind=True, max_retries=3)
def generate_image_task(self, job_id: str, prompt: str, settings: dict):
try:
if settings.get("model") == "dalle":
image = asyncio.run(generate_image_dalle(prompt, **settings))
elif settings.get("model") == "flux":
images = asyncio.run(generate_image_flux(prompt, **settings))
image = images[0]
# Save to S3/MinIO
url = upload_to_storage(job_id, image)
# Notify client
redis_client.publish(f"job:{job_id}", json.dumps({"status": "done", "url": url}))
return url
except Exception as exc:
raise self.retry(exc=exc, countdown=30)
Architecture and Process
We start from the task: analysis → design → implementation → testing → deployment → support. At the start, we capture requirements for quality, speed (p99 latency), and generation volume. Then we select the model, deployment method (API or self-hosted), and GPU configuration. Example: for an e-commerce project with 50,000 generations per day, we deployed a cluster of 4 GPU A100s with a load balancer and Celery queue. p99 latency was 450 ms, cost per image was $0.001. Total development cost from $15,000 to $50,000 depending on complexity.
What's Included in Development
- API documentation with examples (OpenAPI, Postman collection)
- Training your team on using the service
- Operation and monitoring manual
- 3-month warranty support
How Do We Ensure Scaling?
Under loads above 10 RPS, we use an async Celery queue with Redis. Workers run on GPU nodes, results are saved to S3. For 100+ RPS—cluster with load balancer and Ray Serve. This approach provides linear scaling without quality loss. We also use kvrocks for caching repeated requests—this reduces GPU load by 20-30%.
Our engineers have 5+ years in Computer Vision and NLP. We guarantee stable system operation under load. Get a consultation and precise timeline—we'll assess your project in 1 day and propose the optimal solution.
Contact us to discuss the details.
Additionally, when working with Stable Diffusion, we use ControlNet for precise composition control. All solutions are security-tested and optimized for your budget.







