One of the easiest ways to accidentally double-charge users in an AI video API is a naive retry. The submit call times out, you retry, and the upstream created two tasks. Both generate. Both cost money.
The fix is an idempotency key: a unique client-generated token sent with every submit. If the same key is reused, the upstream returns the original task instead of creating a new one.
Implementation checklist:
- Generate the key before the first submit and keep it for the whole task lifecycle.
- Send it in a dedicated header (often Idempotency-Key).
- On timeout or failover to another route, reuse the same key.
- Store the key with your task record for audit and refunds.
Combine this with multi-route failover and you get the best of both: if route A fails, route B picks up the job — but with the same idempotency key, so you never pay twice for one user request.
Small detail, big impact. If your AI video pipeline charges per generation, idempotency is not optional.