Log usage.cost from the Sume images response to CSV in Python
POST /v1/images returns usage.cost as the billed USD amount. A Python logger that writes model, image count and cost per image to a CSV for budget reviews.

The /v1/images response carries a usage object. Token counts are always 0 because Sume meters image models per image, but usage.cost is the real billed USD amount for the call. That one field is enough for a spend log without touching a dashboard.
Two facts shape the logger. First, model echoes the id you requested. Second, a 202 job response has no usage yet, so the logger should skip it and record the cost when the job completes.
Fields to keep
| Field | Meaning |
|---|---|
| model | The requested public id |
| data[].url | Sume-hosted image URLs; count them |
| usage.cost | Billed USD for the whole call |
| usage.total_tokens | Always 0 in v1 |
The logger
Divide cost by the number of images to get a per-image figure that compares across n.
import csv, os, requests
headers = {"Authorization": "Bearer " + os.environ["SUME_API_KEY"]}
def generate(body: dict, path: str = "image-spend.csv") -> None:
r = requests.post("https://api.sume.com/v1/images", headers=headers, json=body, timeout=60)
if r.status_code != 200:
print("not a 200:", r.status_code)
return
j = r.json()
n = len(j["data"])
cost = j["usage"]["cost"]
with open(path, "a", newline="") as f:
csv.writer(f).writerow([j["model"], n, cost, round(cost / n, 5)])
generate({"model": "google/nano-banana-2", "prompt": "Test card", "resolution": "1K", "n": 2})
Reading the log
Billed cost is the provider list price times 1.25. If a month of logs shows a per-image figure far from the catalog's pricing, check whether your calls changed quality, tier or n. For 202 jobs, read the completed job record and log it the same way.
How this was checked
Vendor facts come from the pages listed in the sources, read on 2026-10-05. Sume facts come from the Image API docs and the catalog code on main on the same date. Catalogs and limits change, so read the descriptors from GET /v1/images/models before you pin a number in production code.
Sources
Related posts
More in Developers
- Longest AI video Sume can render: 1800 s from 60 clips
One Timeline render caps at 1800 seconds. With 30-second clips that is 60 clips, with 200 slots allowed. The math and the render price follow.
- Lyria 3.5 prompts for video BGM: section tags and timestamps
Use [Verse]/[Chorus]/[Bridge] tags and [0:00-0:10] timestamps in a Lyria 3.5 prompt to pin an arc to a video. A worked prompt and a Sume call are below.
- macOS launchd: one AI video a day with a per-date Idempotency-Key
A launchd agent that wakes late can run twice. A per-date Idempotency-Key and an existing-file check keep a daily 3 s Gemini Omni clip ($0.1125) to one charge.
- MAI streaming sessions end at one hour: a chunk plan for long audio
A MAI-Transcribe-2-Streaming session lasts at most one hour; Sume STT jobs cap at 10 minutes. Plan overlap-free chunks and shift each chunk's word times.
Written by Sume