Check your Sume balance before a 100-clip batch: Python preflight
Read GET /v1/balance, compare it with the batch estimate and stop before a 402. A runnable Python script for 100 five-second Wan 3.0 clips at $0.625 each.

Before you queue a batch, read the workspace balance and compare it with the batch estimate. Sume's balance endpoint returns available_amount_usd_micros, the spendable amount in USD micros, so the comparison is integer arithmetic.
The estimate
The script assumes 100 clips of 5 seconds each at Wan 3.0 720p, where one clip is $0.625 billed, so the batch needs $62.50 of holds if every job is in flight at once. Change the two constants for another model; take the per-clip value from the models endpoint or the repo estimators.
import json, os, sys, urllib.request
key = os.environ.get("SUME_API_KEY")
if not key:
sys.exit("Set SUME_API_KEY first.")
CLIPS = 100
MICROS_PER_CLIP = 625_000 # Wan 3.0, 720p, 5 s, billed
need = CLIPS * MICROS_PER_CLIP
req = urllib.request.Request(
"https://api.sume.com/v1/balance",
headers={"Authorization": f"Bearer {key}"},
)
with urllib.request.urlopen(req) as resp:
balance = json.load(resp)["data"]["balance"]
have = balance["available_amount_usd_micros"]
print(f"have ${have / 1e6:.2f}, need ${need / 1e6:.2f}, state {balance['state']}")
sys.exit(0 if have >= need else 1)What the check does not cover
- It assumes every job holds at once. If you submit in waves of 20, you only need $12.50 spendable at a time, plus what you spend as waves finish.
- It does not account for retakes. Add a margin for jobs you will re-run.
- A balance read is a snapshot. Other jobs in the same workspace can hold funds between your check and your submit.
Making the script reusable
Pass the per-clip micros and clip count as arguments instead of constants and you can reuse the check across models. Take the per-clip value from the models endpoint when the model has a published pricing line, or from the estimate your submit returns. Keep amounts in integer micros end to end; dividing by a million only for display avoids rounding errors that dollar floats introduce.
Pair the check with an Idempotency-Key on every submit. The docs say not to retry unsafe submit requests without one, and a replay with the same key returns the original job, so a flaky network does not turn into a double charge.
Exit code 1 lets a shell script stop the batch. The error docs say a 402 insufficient_credits is the failure you will otherwise meet at submit time, so the preflight is a courtesy that saves a round trip, not a replacement for handling the 402.
Sources
Related posts
More in Developers
- Choose an image model in code from the Sume catalog's parameters
Filter GET /v1/images/models by what a request needs (references, ratio, transparency), then rank the matches by endpoint price. Python script for Sume.
- Claude batch custom_id is 64 characters: keep SKU keys valid
Anthropic batch custom_id allows 1 to 64 letters, digits, underscore and hyphen. How to sanitize SKUs, avoid collisions and carry the key into Sume input.
- Claude Code 2.1.285 lists WebSocket MCP servers; Sume uses HTTP
Claude Code 2.1.285 shows WebSocket MCP servers in claude mcp list. Sume's hosted MCP is a remote HTTP server, added with --transport http.
- MCP error text showed a Bearer token: rotate the Sume API key
Claude Code 2.1.286 masks credentials after Bearer or Basic in MCP errors. If an old log shows a Sume key, replace it and keep keys out of logs.
Written by Sume