DEV Community

Jackson
Jackson

Posted on

What we learned putting 25 image and video models behind one API

Every image and video model comes with its own request format, its own polling behaviour, its own timeout policy and its own idea of what "done" means. If you are building a product on top of them, that variety is the real cost — not the per-image price.

We built Kerox (https://kerox.ai) to hide that: one HTTP endpoint in front of 25 image and video models — ByteDance Seedance and Seedream, Alibaba Wan and Qwen Image, MiniMax, Kling, GPT Image and others. This post is the part that was not obvious from the outside: how we made a single job model survive models that fail in wildly different ways, and why we settled on "charge only for successful generations".

The shape we standardised on

Almost every provider either returns a result inline or gives you an id to poll. Video models are almost always the second kind, and their queue times vary from two seconds to a few minutes. We compressed both into one job:

curl -X POST https://api.kerox.ai/v1/tasks \
  -H "Authorization: Bearer $KEROX_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "seedream-5.5",
    "input": { "prompt": "a paper boat on wet asphalt, 35mm" }
  }'
Enter fullscreen mode Exit fullscreen mode

You get back a task id, then either poll GET /v1/tasks/{id} or receive a signed webhook. Outputs are served from our CDN for seven days. That is the whole contract; the model name is the only thing that changes between an image job and a video job.

Two decisions inside that contract mattered more than the API surface.

One status vocabulary. Providers disagree about whether a task that timed out is "failed", "cancelled" or "still running". We collapse that into succeeded / failed, and a failure is final. Callers never have to write a state machine per model.

The price is known before the job starts. Every model has a public per-generation price, and the estimate is held against your balance at submit time. For a video model that charges per second, the estimate is computed from the requested duration. You can compare that price against the provider's official rate before you generate, which matters more than it sounds: the spread between models doing similar work is 10x, not 10%.

Why "refund on failure" is a design constraint, not a perk

It is tempting to charge per request and let failed generations be part of the cost of doing business. We did the opposite: the estimated cost is held at submit, released or charged when the task resolves, and a failed or timed-out job is refunded in full.

That sounds generous. In practice it is a forcing function. Once a failed job costs us money instead of the customer, the queue and retry logic get attention: we had to distinguish "provider is slow" from "provider is down", cap retries per task, and stop treating an upstream 5xx as a user error. The side effect is that our own success rate became a number we watch, which is the right incentive when you resell someone else's inference.

There is no subscription and no free tier right now: you top up a USD balance from $5 and it does not expire. We also publish per-model pricing rather than a credit system, because "1 credit = 1 image" hides exactly the comparison developers want to make.

What the API looks like for an agent, not just a person

Most traffic to a service like this is now written by an assistant rather than typed by a human, and assistants are bad at guessing. So the documentation exists in the formats they can actually read: an OpenAPI spec, an llms.txt, markdown docs, and an MCP server. The same account balance is shared by the API and a browser Studio, which is mostly useful for checking a prompt visually before wiring it into code.

If you only take one thing from this post, take the pricing side: per-successful-generation pricing with a public price table turns a fuzzy "how much will this cost" question into a lookup, and it makes the provider's reliability the vendor's problem. That is the part we would keep if we started again.

Kerox is at https://kerox.ai if you want to try the API; the model list and the official-vs-Kerox price comparison are public without an account.

Top comments (0)