Python http.client: POST /v1/images on Sume with the standard library
Call Sume's image API from Python using only http.client and json: a 40-second timeout, and branches for 200, 202 and error responses.

When you cannot pip install anything, the standard library is enough.
The request is the same in every language: POST https://api.sume.com/v1/images with a bearer key from SUME_API_KEY, a JSON body with model, prompt and aspect_ratio, and a client timeout above the route's 30-second wait. The route defaults to mode: "sync", so the status code decides what you do next (docs read 2026-10-07):
Status codes to branch on
| Status | Meaning | What the code below does |
|---|---|---|
| 200 | Image finished inside the wait; data[].url holds the file | Prints the result |
| 202 | Wait expired (or mode is async or webhook); body is a job envelope with status_url and result_url | Prints the envelope; poll status_url and read result_url |
| 502 | The job failed inside the wait; error has code, retryable, next_action | Prints the error |
| 400, 404 | unsupported_parameter, or model_not_found | Prints the error |
Python code
Save as hc.py and run SUME_API_KEY=... python3 hc.py. No packages to install, no top-level await.
import http.client, json, os
key = os.environ["SUME_API_KEY"]
body = json.dumps({
"model": "bytedance-seed/seedream-5-lite",
"prompt": "matte ceramic mug on a white sweep, soft shadow",
"aspect_ratio": "16:9",
})
conn = http.client.HTTPSConnection("api.sume.com", timeout=40)
conn.request("POST", "/v1/images", body, {
"Authorization": "Bearer " + key,
"Content-Type": "application/json",
})
res = conn.getresponse()
text = res.read().decode()
if res.status == 200:
print("done:", json.loads(text)["data"][0]["url"])
elif res.status == 202:
print("queued, follow status_url:", text)
else:
print("error", res.status, text)
conn.close()Notes
The timeout on HTTPSConnection is a socket timeout, applied to each blocking operation; 40 seconds is above Sume's 30-second sync wait.
Check res.status before parsing: only a 200 body has data[0].url.
One bytedance-seed/seedream-5-lite image is $0.04375 billed (list $0.035 x 1.25). Prices here are Sume's list-times-1.25 figures. The catalog states the billable formula as "list × 1.25 → ceil usd cents", so treat the dollar amounts as the pre-rounding value and read the exact charge from billable_amount_usd_micros in the submit envelope. Failed or cancelled generations are not billed.
Sources: Sume Image API docs and Jobs and results (read 2026-10-07).
Sources
Related posts
More in Developers
- Python: cheapest Sume image model that lists your aspect ratio
A 25-line Python script reads Sume's image catalog, keeps models that list your aspect ratio, prices each from its endpoints record and prints the cheapest.
- Python preflight for a Sume bulk body: count, keys, bytes, caps
Check a Sume bulk-run body offline before the POST: 1 to 100 items, concurrency 1 to 16, 64 input keys, 2 MiB input, 4 MiB body and a spend cap in range.
- Sume job webhook receiver in plain Python, no framework
A 30-line stdlib http.server receiver for Sume job webhooks: raw-body HMAC, 300-second window, rotation-safe header, refuses an empty secret, answers 204.
- Python ThreadPoolExecutor: submit 12 Wan 3.0 clips, four at a time
Stdlib-only Python: ThreadPoolExecutor with 4 workers posts Wan 3.0 jobs to /v1/videos, one Idempotency-Key per shot, results printed in completion order.
Written by Sume