Skip to content

Generate

One call per cloud. Every parameter shown here — model id, size, aspect ratio, quality, response encoding — was verified against the live docs cited on this page.

Official docs verified 2026-08-08

The call

Each provider returns image bytes (or base64) — the service helper decodes/normalizes to raw PNG bytes so the app treats them uniformly downstream.

client.images.generate on the standard openai package pointed at your Azure OpenAI base URL. Same SDK you use for chat + embeddings.

import base64, os
from openai import AzureOpenAI

client = AzureOpenAI(
    api_key=os.environ["AZURE_OPENAI_API_KEY"],
    azure_endpoint=os.environ["AZURE_OPENAI_ENDPOINT"],
    api_version=os.environ.get("AZURE_OPENAI_API_VERSION", "2025-04-01-preview"),
)

resp = client.images.generate(
    model=os.environ.get("AZURE_IMAGE_DEPLOYMENT", "gpt-image-1"),
    prompt="a close-up of a bear walking through a fog-shrouded forest",
    n=1,
    size="1024x1024",       # 1024x1536 / 1536x1024 also supported on GPT-Image-1 family
    quality="high",         # low | medium | high
    output_format="png",    # png | jpeg
)
png_bytes = base64.b64decode(resp.data[0].b64_json)

Note: Azure OpenAI image generation only returns base64 (no url in Azure's variant), so the app always decodes.

client.models.generate_images on the unified google-genai client.

import os
from google import genai
from google.genai import types

client = genai.Client(
    vertexai=True,
    project=os.environ["GOOGLE_CLOUD_PROJECT"],
    location=os.environ.get("GOOGLE_CLOUD_LOCATION", "us-central1"),
)

resp = client.models.generate_images(
    model=os.environ.get("VERTEX_IMAGE_MODEL", "imagen-4.0-generate-001"),
    prompt="a close-up of a bear walking through a fog-shrouded forest",
    config=types.GenerateImagesConfig(
        number_of_images=1,
        aspect_ratio="1:1",   # 1:1 | 3:4 | 4:3 | 9:16 | 16:9
    ),
)
png_bytes = resp.generated_images[0].image.image_bytes

Bedrock Nova Canvas via boto3 invoke_model. Response body is JSON with a Base64-encoded PNG list.

import base64, json, os, boto3
from botocore.config import Config

# Nova Canvas generation can exceed the default 60s read timeout on
# high-res / high-count calls; bump it up.
client = boto3.client(
    "bedrock-runtime",
    region_name=os.environ.get("AWS_REGION", "us-east-1"),
    config=Config(read_timeout=300),
)

body = json.dumps({
    "taskType": "TEXT_IMAGE",
    "textToImageParams": {
        "text": "a close-up of a bear walking through a fog-shrouded forest",
    },
    "imageGenerationConfig": {
        "width":  1024,
        "height": 1024,
        "quality": "standard",     # standard | premium
        "cfgScale": 6.5,           # 1.1 – 10.0
        "numberOfImages": 1,
    },
})
resp = client.invoke_model(
    modelId=os.environ.get("BEDROCK_IMAGE_MODEL", "amazon.nova-canvas-v1:0"),
    body=body,
    accept="application/json",
    contentType="application/json",
)
payload = json.loads(resp["body"].read())
png_bytes = base64.b64decode(payload["images"][0])

A common signature

The service exposes:

def generate_image(prompt: str, *, width: int = 1024, height: int = 1024) -> bytes: ...

Returns raw PNG bytes. CHIRON_PROVIDER picks the backend. See examples/image/service/ for the exact implementation.

Run + verify (local, with your own creds)

pip install openai google-genai boto3
CHIRON_PROVIDER=azure python -c "from generate import generate_image; open('out.png','wb').write(generate_image('a bear'))"