GPT Image 2.5 Python example: generate an image with the Sume API

A runnable Python example for GPT Image 2.5 on Sume: async httpx, POST /v1/images, read data[].url, and stop cleanly on a 202 job. Copy, set the key, run.

3 min readSume
All posts

This is a complete Python script that generates one image with GPT Image 2.5 through Sume: it posts to https://api.sume.com/v1/images, prints the image URL on a 200, and prints the job URL on a 202 so you can poll it. It needs httpx and a SUME_API_KEY environment variable.

Request and response shapes come from Sume's Image API docs and Jobs and results, read 2026-09-29.

What does the script look like?

import asyncio, os
import httpx

async def main() -> None:
    headers = {"Authorization": f"Bearer {os.environ['SUME_API_KEY']}"}
    body = {
        "model": "openai/gpt-image-2.5",
        "prompt": "a lighthouse on a cliff at dusk, oil painting",
        "quality": "medium",
        "image_size": "1536x1024",
    }
    async with httpx.AsyncClient(timeout=60) as client:
        r = await client.post("https://api.sume.com/v1/images", headers=headers, json=body)
    if r.status_code == 200:
        for image in r.json()["data"]:
            print(image["url"])
    elif r.status_code == 202:
        print("still running:", r.json()["data"]["status_url"])
    else:
        r.raise_for_status()

asyncio.run(main())

Why check the status code?

A 200 carries the images; a 202 carries a job. The docs say to check the status code, not the body shape. On 202, poll status_url, then read result_url.

Response handling in the script, from the Image API docs, read 2026-09-29.
StatusBodyScript prints
200data[].url per imageEach image URL
202Job envelope with status_urlThe status URL
OtherError bodyRaises httpx.HTTPStatusError

Which size did the example use?

1536x1024: both edges are multiples of 16 and the total is 1,572,864 pixels, inside the 655,360 to 8,294,400 range.

Sources

Related posts

More in Developers

All Developers posts

Written by Sume