A dry-run flag for Sume API calls: print the request, skip the spend
Add DRY_RUN to code that calls the Sume API: build the body, key and spend cap, print them, and send nothing. Review a batch before it costs money.

A dry-run flag is the cheapest cost control you can write for a Sume integration: build every request exactly as you would send it, print the body, idempotency key and spend cap, and stop before the network call. A reviewer can then read a whole batch before anything is charged.
Why print the cap
The Sume best-practices page says to cap spend on every run with generation_spend_cap_usd and to treat a missing cap as a bug in the client. A dry run that prints the cap makes a missing one visible in review, not on the invoice.
import asyncio, json, os
DRY_RUN = os.environ.get("DRY_RUN", "1") != "0"
async def submit(client, path: str, body: dict, key: str) -> None:
if "generation_spend_cap_usd" not in body:
raise ValueError("every run needs generation_spend_cap_usd")
if DRY_RUN:
print(json.dumps({"path": path, "key": key, "body": body}, indent=2))
return
r = await client.post(path, json=body, headers={"Idempotency-Key": key})
r.raise_for_status()
async def main() -> None:
body = {"input": {"product_url": "https://shop.example.com/p/1"},
"generation_spend_cap_usd": 3}
await submit(None, "/v1/formats/acme/product-promo/runs", body, "order-1-v1")
asyncio.run(main())Default to dry
Default the flag to on, and require an explicit DRY_RUN=0 for a real run, so a copied script never spends by accident. This is a guard in your code; it does not call Sume, so it cannot tell you a price.
What it does not replace
The cap bounds one run, and the balance gate returns 402 insufficient_credits before provider work starts. Dry runs complement them by catching mistakes earlier, such as a loop that submits the same item twice.
| Layer | Control | Catches |
|---|---|---|
| Before the call | Dry run and review | Wrong batch size, missing cap |
| On the run | generation_spend_cap_usd | Runaway single run |
| On the account | Balance and 402 | Spending beyond funds |
Sources
Related posts
More in Developers
- Dub one Short into 8 languages: Python fan-out and the total cost
Detach and transcribe once, then run one TTS job and one render per language. A Python fan-out and the per-Short bill, from Sume's catalog rates.
- eBay Media API video upload: 150 MB, MP4, and the LIVE status
eBay's Media API takes a listing video in two calls: createVideo with the exact byte size (max 150 MB), then uploadVideo as MP4. Prep the file with Sume.
- Edge Add-ons screenshots: 640x480 or 1280x800, up to 6
Edge accepts up to 6 screenshots at 640 x 480 or 1280 x 800. 640 x 480 is 4:3, which Sume lists; 1280 x 800 is 16:10, so crop a 16:9 source.
- Edge Add-ons small tile 440x280: crop a 3:2 Sume image
Edge's small promotional tile must be exactly 440 x 280, a 1.571 ratio. Sume lists 3:2 for FLUX.2 Pro, so crop 4.5% of the height and resize.
Written by Sume