Nova Canvas returned fewer images than asked: Sume n and data length

Nova Canvas can return fewer images than numberOfImages when moderation blocks some. How to count what you got and what you paid for on Sume.

4 min readSume
All posts

Ask Nova Canvas for four images and you may get three. Amazon's docs (read 2026-10-06) say numberOfImages can return fewer images when responsible-AI moderation blocks some of them. Code that assumes four will index past the end of the list.

The Sume equivalent

n on Sume works the same way from the caller's side: you ask for a count, the response has a data array, and the per-model maximum comes from the catalog. The safe pattern is to never assume len(data) == n. Count the array and divide the billed amount by the count when you track cost per image.

usage.cost is the billed USD amount. A job that fails terminally returns a 502 error envelope with category, retryable and next_action, and failed jobs are not billed. For a slow request the response is a 202 job envelope, and the images come from the result URL, not from the first response.

Count first, then price

The function below handles three outcomes: a full result, a short result and a job that is still running.

import os, requests

def edit(n: int):
    r = requests.post(
        "https://api.sume.com/v1/images",
        headers={"Authorization": f"Bearer {os.environ['SUME_API_KEY']}"},
        json={"model": "google/nano-banana-2", "n": n,
              "prompt": "Same mug, new table settings.",
              "input_references": [{"type": "image_url", "image_url": {"url": "https://example.com/mug.jpg"}}]},
        timeout=90)
    if r.status_code == 202:
        return None, r.json()
    r.raise_for_status()
    body = r.json()
    got = len(body["data"])
    per_image = body["usage"]["cost"] / got if got else 0
    return got, per_image

print(edit(4))

What to log

Log requested n, returned count and usage.cost on every call. A gap between the first two on a prompt that keeps coming back short usually points at the prompt, and it is cheaper to rewrite the prompt than to retry.

Sources

Related posts

More in Developers

All Developers posts

Written by Sume