One Image to Cinematic Video: Why We Built a Multi-Route AI Pipeline
Turning a single still image into a usable video clip sounds like a solved problem — until you run it in production, for strangers, every minute of the day. A demo works when one model is up, one account has quota, and
Turning a single still image into a usable video clip sounds like a solved problem — until you run it in production, for strangers, every minute of the day.
A demo works when one model is up, one account has quota, and one price list is stable. A production service needs to survive model removals, price changes, account-level rate limits, and upstream jobs that sit in a queue forever without ever failing. This is what we learned building a multi-route video generation pipeline.
The problem with a single model
Every upstream model has a lifecycle. It gets renamed, repriced, restricted to certain accounts, or quietly stops executing jobs. When that happens, a single-route integration does not degrade gracefully — it just breaks.
We saw three distinct failure modes:
- Model or price disappeared. The request was rejected before generation, but the error was an opaque English string that meant nothing to an end user.
- Queued but never started. The upstream accepted the job, returned a task ID, and then held it at zero progress. No failure event, no refund trigger, no completion.
- Explicit rejection. Content policy, invalid media, busy upstream. These are real failures and should move the job to another route immediately.
The temptation is to treat all three the same. That is a mistake — the right reaction depends on whether you know the upstream failed.
The design: a virtual model over many real routes
Users pick one model name. Behind it sits a group of real channels, ordered by priority. Each channel has its own credentials, model mapping, and price table.
On submit, the pipeline works in stages:
- Preflight validation, no upstream call. Check model mapping, price table, allowed duration tiers, and model availability. If a route is invalid, skip it before creating any upstream job — no cost, no orphan task.
- Submit to the active route. The upstream task ID is stored against the same local job, so a failover never creates a new customer-facing task.
- Poll for a definitive result. Success, explicit failure, or "unknown". Only a definitive failure triggers a switch to the next route.
- Last route fails → refund. Until then, credits stay frozen and the job simply moves on.
The key rule: failover only on a known failure. A network timeout or a missing status is not a failure. If we cannot detect an upstream result after a long window, we do not silently refund and we do not mark the job failed — we surface it as an operator to-do and keep polling. That single decision removed a whole class of false refunds.
Queued-forever detection
The hardest bug was not a crash; it was a job that looked alive. The upstream returned a task ID and a queued status, but progress stayed at zero and execution_ready was false. A plain timeout would have killed a potentially valid job.
We added a state check: a job that is still queued with zero progress after a long grace period gets one read-only probe of its content endpoint. If the probe says there is no execution path, that route is marked as failed and the job moves on. If the probe is inconclusive, the job stays alive and keeps polling.
A subtle follow-up bug: after we marked the route failed, a later queued poll overwrote the failure back to queued. The fix is a one-way latch — once a route is definitively failed, later optimistic statuses from that route are ignored.
Billing across routes
Multi-route only works if pricing is consistent from the user's point of view. We keep one customer-facing price table per virtual model, and map each route onto it.
Two details mattered:
- Price lookups use each channel's own credentials. Two accounts on the same upstream can see different model lists and different prices. Asking with one key and applying the answer to another route produced false "no price" failures.
-
Reference media can have its own rate. For image-heavy work, the cost is
video seconds × video rate + reference video seconds × reference rate. Showing that formula in the submit dialog before the user pays avoids almost every billing dispute.
Duration tiers are another trap. Old fixed-duration keys can survive a price-table update and keep overriding the new tiers. We now derive allowed durations from the effective price table and clean stale entries whenever prices are saved.
Observability and user-facing errors
Every skipped route writes a reason into the admin task record: which check failed, and whether an upstream job was ever created. That distinction is essential when a customer asks "was my job submitted?"
The customer sees a short localized message instead. Upstream model names, raw prices, vendor brands, and stack traces are stripped before display; the full upstream response stays in the admin record. A generic "service busy" now becomes a plain-language message with the refund status stated explicitly.
Who actually uses this
- Comics and serialized drama: one prompt, continuous shots, consistent characters across scenes.
- E-commerce: product stills turned into short ads, with per-second pricing that makes batch cost predictable.
- Remix and replication: drop in a reference clip, swap the character, scene, or style; reference media is billed by its own duration.
Takeaways
If you are putting generative models behind a public API:
- Validate before you submit. A rejected preflight costs nothing; a rejected upstream job can cost real money.
- Distinguish "definitely failed" from "unknown" — they need different business logic.
- Treat forever-queued as a first-class failure state, with a read-only probe and a one-way latch.
- Price per virtual model, not per vendor, and derive UI tiers from the effective price table.
- Log the skip reason internally, but never leak upstream details to the customer.
Reliability here is less about picking the best model and more about handling the moment it stops being available.
Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.