Contract test for 1:4, 4:1, 1:8, 8:1: pytest on /v1/images/models

A 12-line pytest that fails CI if Sume stops listing the Nano Banana 2.1 strip ratios. It reads GET /v1/images/models, so it generates nothing.

3 min readSume
All posts

If your product ships banners at 8:1, a catalog change that drops the ratio would show up as 400 unsupported_parameter in production. A pytest against GET /v1/images/models catches it in CI before that: the endpoint lists each model's aspect_ratio values, and the test asserts that 1:4, 4:1, 1:8 and 8:1 are still in the google/nano-banana-2.1 row. It generates no image.

The test

Sume documents supported_parameters as capability descriptors, and the aspect_ratio descriptor is an enum with a values list.

import os, requests

NEED = {"1:4", "4:1", "1:8", "8:1"}

def test_banana_lists_strip_ratios():
    r = requests.get(
        "https://api.sume.com/v1/images/models",
        headers={"Authorization": f"Bearer {os.environ['SUME_API_KEY']}"},
        timeout=30,
    )
    r.raise_for_status()
    row = next(m for m in r.json()["data"] if m["id"] == "google/nano-banana-2.1")
    listed = set(row["supported_parameters"]["aspect_ratio"]["values"])
    assert NEED <= listed, f"missing: {NEED - listed}"

What the check pins

Ratios the test expects (read 2026-10-09)
RatioMeaningListed on Nano Banana 2.1 in the repo catalog
1:4Tall stripYes
4:1Wide stripYes
1:8Very tall stripYes
8:1Very wide stripYes

Gotchas

  • Use a key with access to the Image API; read-only CI can use a separate key.
  • next(...) raises StopIteration if the model row disappears. That is a failure you want, but wrap it with a clearer message if you prefer.
  • The test proves the catalog; it does not prove an image renders as you expect.

Sources

Related posts

More in Developers

All Developers posts

Written by Sume