Image Generation
Generate images using Kie.ai’s Nano Banana Pro model with support for image transformation.Create Generation Task
Initiate an image generation task.Request
Image generation prompt (detailed description of desired image)
Image aspect ratioOptions:
1:1, 2:3, 3:2, 3:4, 4:3, 4:5, 5:4, 9:16, 16:9, 21:9, autoImage resolutionOptions:
1K, 2K, 4KInput image URLs for transformation (max 8 images)Use this to modify existing images or create variations.
Response
Unique task ID for polling status
Kie.ai Request Format
The API forwards requests to Kie.ai:Check Task Status
Poll for task completion and retrieve the generated image URL.Task ID from create task response
Response
Task ID
Task state:
pending, processing, success, or failGenerated image URL (only available when
state: "success")Error message if
state: "fail"Generation time in milliseconds
Task States
| State | Description | Action |
|---|---|---|
pending | Task queued or waiting | Continue polling |
processing | Image being generated | Continue polling |
success | Image ready | Retrieve imageUrl |
fail | Generation failed | Check failMsg |
Polling Pattern
Poll the status endpoint until the task completes:- Max attempts: 90
- Interval: 3 seconds
- Total timeout: 4.5 minutes
Generation Time: Most images complete in 30-90 seconds. Complex infographics may take up to 2-3 minutes.
Image Transformation
Modify existing images by providing them as input:Array of image URLs to use as input (max 8 images)Use cases:
- Recolor existing infographic
- Add/remove elements
- Change layout or composition
- Merge multiple images
Transformation Examples
Aspect Ratios
Supported aspect ratios and common use cases:| Ratio | Dimensions | Use Case |
|---|---|---|
1:1 | Square | Instagram posts, profile images |
16:9 | Landscape | LinkedIn posts, presentations, blog headers |
9:16 | Portrait | Instagram Stories, TikTok |
4:5 | Portrait | Instagram feed posts |
21:9 | Ultrawide | Cinematic presentations |
3:2 | Photo | Standard photography format |
auto | Dynamic | Let model decide optimal ratio |
Resolutions
| Resolution | Dimensions | File Size | Use Case |
|---|---|---|---|
| 1K | ~1024px | ~200KB | Web thumbnails, previews |
| 2K | ~2048px | ~500KB | Social media, web display |
| 4K | ~4096px | ~2MB | Print, high-res displays |
Default:
2K provides good balance between quality and file size for most social media use cases.Error Responses
| Status | Error | Description |
|---|---|---|
400 | Prompt is required | Missing or empty prompt |
400 | taskId is required | Missing taskId in status check |
400 | Kie.ai error | Upstream API error (check message) |
500 | Kie.ai API key not configured | Missing KIEAI_API_KEY |
500 | Failed to start image generation | Request processing error |
500 | Failed to check task status | Status check error |
Prompt Engineering
Effective prompts for infographics:Good Prompt Structure
Style Keywords
- Visual style:
isometric 3D,flat design,minimalist,cinematic,data visualization - Mood:
professional,bold,modern,tech-forward,premium - Composition:
centered,asymmetric,grid layout,hero image
Brand Consistency
For YBH-branded images:Service Integration
For service-level usage, see:- Kie.ai Service Reference - TypeScript functions and polling utilities
Rate Limits & Costs
No Built-in Limits: The API does not enforce rate limits. Implement client-side throttling to control costs.
Common Issues
Task Times Out
If a task exceeds 4.5 minutes:- Check Kie.ai dashboard for task status
- Increase
maxAttemptsorintervalMsin polling - Simplify the prompt (complex requests take longer)
Image URL is Null
Ifstate: "success" but imageUrl is null:
- Check Kie.ai API response structure
- Wait a few seconds and poll again
- Contact Kie.ai support if persistent
Generation Fails
Common failure reasons:- Prompt violates content policy
- Input image URLs are inaccessible
- Kie.ai service outage
failMsg for details.