← Binderdex dev log

The backfill that ran out of tokens

#ai-agents#product#automation

Six large dashed circles, each with a small amber dot at its centre, spilling past the edges of a red-outlined box

An hour into a backfill, with 58 painted backdrops done, my image provider returned a 402 and stopped. There was still money in the account. The generations were never the problem. The reservations were.

Binderdex is a Pokémon card collection and price app. It has a gallery of binder ideas, which are ready-made themed pages of nine cards. The backfill was a one-off job that painted a backdrop for every idea that already existed. A 402 is the HTTP status for "payment required", and a reservation is money the provider sets aside for a request before it knows the real cost.

Why the cards needed a backdrop

Social posts for Binderdex used to show a 3x3 card grid on a blurred card background, and it read flat. Now, for every binder idea, a vision model looks at the card art and writes a scene brief, a short description of a setting with no card names in it. An image model paints it. A second vision pass rejects anything with creatures, figures, text or frames before the backdrop is stored. What survives shows up on X posts, Pinterest pins, the idea page and the app's share image.

A metered API reserves the worst case

The 402 came back as in_flight_budget_exhausted, the provider's way of saying my requests still running had already reserved the whole balance. I had never set max_tokens, the cap on how much a request can produce, so every in-flight request reserved its model's worst-case cost against the balance. Six concurrent requests were enough to exhaust it. The fix is one argument, plus treating the 402 like a rate limit:

# worst-case reservation happens when max_tokens is unset
resp = generate_image(prompt=brief, max_tokens=MAX_TOKENS)
if resp.status == 402:          # budget exhausted, not a hard failure
    retry_with_backoff(resp)    # same lane as a 429

I also dropped the backfill to three concurrent requests. A metered provider holds what your request might use, whatever it ends up using. Uncapped concurrency on top of uncapped reservations can fail you with a healthy balance.

Three tries, then the old background

Generation failures are normal, so a brief that fails three times stops there. There is no queue and no retry loop. The post falls back to the old blurred-card background, and quality stays a gate.

This is the build log for Binderdex (www.binderdex.com) · All entries · Weekly essays