Images

Generate images with Flux, Nano-Banana, or gpt-image-1.5 — same endpoint, same response shape as the OpenAI Images API. The model parameter selects the upstream; everything else (prompt, size, n, response_format) works as you'd expect.

Generate an image

from openai import OpenAI

client = OpenAI(
    base_url="https://api.echotokens.com/v1",
    api_key="sk-echo-...",
)

response = client.images.generate(
    model="flux-2-pro",
    prompt="A pelican wearing a tweed jacket, oil painting, dramatic lighting.",
    size="1024x1024",
    n=1,
)

print(response.data[0].url)
print(f"Cost: {response.cost_usd_cents} cents")

Returned images are either url (a CDN link valid for ~24 hours) or b64_json (a base64-encoded PNG, useful when you want to skip the download round-trip). Set response_format="b64_json" to switch.

Picking a model

  • flux-2-pro — sharp photoreal output, fast turnaround. Good default for marketing assets.
  • flux-2-ultra — higher fidelity for hero imagery and product shots; takes longer.
  • nano-banana-2 — stylized illustration. Strong on character art and editorial.
  • gpt-image-1.5 — best instruction-following for text-in-image and layout-aware prompts.

All four accept the same parameter set. Switch models by changing one string.

Sizes

The OpenAI SDK accepts "1024x1024", "1024x1792", and "1792x1024" for portrait/landscape. Some upstream providers support additional aspect ratios — pass them as strings and the gateway forwards the request when the upstream allows it. Unsupported sizes return a 400 with a clear error message.

Image edits

Most image models support an edits endpoint that takes an input image plus a mask:

with open("input.png", "rb") as image, open("mask.png", "rb") as mask:
    result = client.images.edit(
        model="flux-2-pro",
        image=image,
        mask=mask,
        prompt="Replace the sky with a starlit night.",
        n=1,
        size="1024x1024",
    )

print(result.data[0].url)

The mask is a PNG where transparent pixels mark the area to regenerate; opaque pixels are kept. Both the image and mask must be the same dimensions.

bill awareness

Image generations are an order of magnitude more expensive than chat tokens. A single flux-2-ultra call can run 4-12 cents depending on resolution. Watch the cost_usd_cents field while you iterate on prompts — the usage page shows per-request cost so you can ballpark a batch run before you launch it.