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.

4 min readSume
All posts

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

Response fields for a spend log (read 2026-10-05)
FieldMeaning
modelThe requested public id
data[].urlSume-hosted image URLs; count them
usage.costBilled USD for the whole call
usage.total_tokensAlways 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

All Developers posts

Written by Sume