Image Generation

Supported Models

ModelProviderMax SizeNotes
azure/flux-kontext-proAzure (FLUX)1440x1440Flux Kontext Pro, high quality
google/imagen-4.0Google Vertex2048x2048Google Imagen 4
google/imagen-4.0-fastGoogle Vertex2048x2048Faster variant
google/imagen-4.0-ultraGoogle Vertex2048x2048Highest quality
bailian/wan2.7-imageAlibaba Bailian1024x1024Wanxiang image generation
bailian/wan2.7-image-proAlibaba Bailian1024x1024Pro variant
azure/mai-image-2Azure2048x2048Microsoft MAI Image 2
bedrock/stability-*Amazon Bedrock1024x1024Stability AI models

Text-to-Image

Request

POST https://api.chuizi.ai/v1/images/generations

Parameters

ParameterTypeRequiredDefaultDescription
modelstringYes--Model name
promptstringYes--Image description
sizestringNo"1024x1024"Image dimensions
response_formatstringNo"url"url or b64_json

Size Options

SizeAspect RatioSupported Models
1024x10241:1 (square)All models
1792x102416:9 (landscape)Most models
1024x17929:16 (portrait)Most models
2048x20481:1 (large square)Imagen, MAI Image

Example

terminal
bash
curl -X POST https://api.chuizi.ai/v1/images/generations \
  -H "Authorization: Bearer ck-your-key-here" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "azure/flux-kontext-pro",
    "prompt": "A minimalist logo design for a coffee shop called 'Morning Brew', clean lines, warm colors",
    "size": "1024x1024",
    "n": 1
  }'

Response

config.json
json
{
  "created": 1712000000,
  "data": [
    {
      "url": "https://media.chuizi.ai/images/gen-xxxxxxxxxxxxxxxx.png"
    }
  ],
  "x_chuizi": {
    "generation_id": "gen-xxxxxxxxxxxxxxxx",
    "cost": "0.05000000",
    "latency_ms": 8500
  }
}

The url is a permanent link hosted on the R2 CDN. It does not expire.

Base64 Response

Set response_format to "b64_json" to receive the image as a base64-encoded string instead of a URL:

config.json
json
{
  "model": "azure/flux-kontext-pro",
  "prompt": "A red sunset over mountains",
  "response_format": "b64_json"
}

Response:

config.json
json
{
  "created": 1712000000,
  "data": [
    {
      "b64_json": "iVBORw0KGgoAAAANSUhEUgAA..."
    }
  ]
}

Use base64 when you need to process the image immediately without downloading from a URL.

Image Editing

Edit existing images with text instructions using POST /v1/images/edits:

terminal
bash
curl -X POST https://api.chuizi.ai/v1/images/edits \
  -H "Authorization: Bearer ck-your-key-here" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "qwen/qwen-image-edit-plus",
    "image": "iVBORw0KGgo...(base64)",
    "prompt": "Change the background to a beach sunset",
    "size": "1024x1024"
  }'

Parameters

ParameterTypeRequiredDescription
modelstringYesModel name (must support editing)
imagestringYesSource image as base64, with or without a data:image/...;base64, prefix
promptstringYesEditing instruction
sizestringNoOutput size (default: same as input)

Response

Same format as image generation:

config.json
json
{
  "created": 1712000000,
  "data": [
    {
      "url": "https://media.chuizi.ai/images/gen-xxxxxxxxxxxxxxxx.png"
    }
  ]
}

Code Examples

example.py
python
from openai import OpenAI
import base64
import requests

client = OpenAI(
    base_url="https://api.chuizi.ai/v1",
    api_key="ck-your-key-here",
)

# Generate an image
response = client.images.generate(
    model="azure/flux-kontext-pro",
    prompt="A futuristic cityscape at night, neon lights, cyberpunk style, detailed",
    size="1792x1024",
    n=1,
)
print(f"Image URL: {response.data[0].url}")

# Generate multiple images
response = client.images.generate(
    model="google/imagen-4.0-fast",
    prompt="A watercolor painting of a mountain lake at sunrise",
    size="1024x1024",
    n=4,
)
for i, image in enumerate(response.data):
    print(f"Image {i + 1}: {image.url}")

# Edit an existing image with JSON/base64
with open("photo.png", "rb") as file:
    image_b64 = base64.b64encode(file.read()).decode("utf-8")

edit_response = requests.post(
    "https://api.chuizi.ai/v1/images/edits",
    headers={
        "Authorization": "Bearer ck-your-key-here",
        "Content-Type": "application/json",
    },
    json={
        "model": "qwen/qwen-image-edit-plus",
        "image": image_b64,
        "prompt": "Add a rainbow in the sky",
        "size": "1024x1024",
    },
).json()
print(edit_response["data"][0].get("url"))

Tips

  • Be specific in prompts. Include style ("watercolor", "photorealistic", "minimalist"), subject, lighting, and composition for better results.
  • Use the right size for your use case. Square (1024x1024) for avatars and thumbnails. Landscape (1792x1024) for headers and banners. Portrait (1024x1792) for mobile backgrounds.
  • CDN URLs are permanent. Unlike some providers that expire image URLs after 1 hour, Chuizi.AI stores images permanently on R2 CDN. You can reference them directly in your application.
  • Image generation is billed per request, not per token. Check the pricing page for per-model costs. Generating 4 images (n=4) costs 4x the single-image price.
  • Use b64_json for server-side processing. If you immediately resize, crop, or transform the image, base64 avoids an extra download step.

Next Steps

Image Generation — Chuizi AI Docs | Chuizi AI