AI Video API Error Codes: What to Retry
AI video API error codes explained: what each status and code means, which to retry, which cost nothing, and a retry loop that never pays twice.
Updated 6 min read
AI video API error codes come back in two places: as an HTTP status with a JSON code when a request is refused, or on the job itself when a clip fails after it was accepted. Retry 429, 500 and 503 with the same Idempotency-Key, fix the request before you resend a 400, 401 or 402, and stop worrying about the bill: on Frameport, nothing refused and nothing failed is ever charged.
This page lists every code the API returns, what each one means, which are worth a retry, how content refusals differ from errors, and a retry loop you can paste into your own code. The codes are the same for every model, so a Seedance 2.5 script and a Veo 3.1 script handle them the same way.
Two places errors show up: the HTTP answer and the job
A request that starts work, such as POST /v1/videos/generations, is checked before anything is held on your balance. If it cannot run, you get a 4xx or 5xx status right away, with this body:
{
"error": {
"code": "insufficient_balance",
"message": "Your balance does not cover this request. Nothing was charged.",
"request_id": "req_7Xc2LmQ9vT4nRk8Ws1Bd"
}
}Branch on code, which never changes for a given case. Show or log message, which says what to fix in plain words. Keep request_id (also sent as the X-Request-Id header): it is what support needs to find your call.
If the request passes, it answers 202 Accepted with a generation that is queued. From then on, a problem is no longer an HTTP error. The clip renders, and it ends succeeded or failed; a failed one carries the reason in its error field and costs nothing. Your code needs both paths: one for refused requests, one for jobs that fail later.
AI video API error codes at submit
These are the answers a submit can get. All of them hold nothing and charge nothing.
| Status | Code | What it means | Retry? |
|---|---|---|---|
| 400 | invalid_request | A field is missing, mistyped or off the model's grid (a length, resolution or aspect ratio it does not make). The message names the field and what the model takes. | No: fix the field |
| 400 | model_not_found | Unknown model id, or a model sent to the wrong endpoint: a video model to the image route, a clip editor to a generation route. | No |
| 400 | content_policy | The model's maker refused the request. | No: reword or pick another model |
| 400 | content_filtered | Your workspace's content filter refused the prompt. | No |
| 400 | invalid_input | A picture you sent could not be used. | No: send another picture |
| 400 | invalid_video | The clip of a clip edit could not be used: its address, format, length, size or frame rate. | No: convert the clip |
| 400 | max_cost_exceeded | The price is above the max_cost_usd you set. | No: raise the cap or shrink the clip |
| 400 | file_expired | An upload or file named in the request is gone. | No: upload it again |
| 401 | unauthorized | Missing, invalid or revoked key. | No: check the key |
| 402 | insufficient_balance | The balance does not cover the price held at submit. | After a top-up |
| 409 | idempotency_conflict | This Idempotency-Key was already used with a different body. | No: use a new key |
| 409 | request_in_progress | The first request with this key has not answered yet. | Yes, after Retry-After |
| 413 | invalid_request | The body is over 16 MB. Send pictures by URL or upload them. | No |
| 429 | rate_limited | Past the workspace's requests a minute (60). | Yes, after Retry-After |
| 429 | concurrency_limit | Too many generations running at once (20 per workspace). | Yes, when one finishes |
| 500 | internal_error | Something broke on our side. | Yes, with the same key |
| 503 | model_unavailable | This model cannot take work right now. | Yes, later |
| 503 | service_unavailable | The service cannot take work right now. | Yes, later |
Two details answer common searches. There is no 422 here: a body the API cannot accept is a 400 invalid_request whose message points at the field. And the API never answers 502. When a model or the service is down, the answer is a 503 with the JSON body above, so a "request failed 502" error with an HTML page comes from something between you and the API (a proxy, a load balancer), not from the API itself.
Reads have a few codes of their own: 403 forbidden for a signed file link that has expired (read the generation again for a fresh one), 404 not_found for an id that does not belong to your workspace, 409 not_ready when you download a file that is not finished, and 410 file_expired for a file that is no longer stored. The errors reference lists every status with its exact wording.
Jobs that fail after they start
Once a request is accepted, the job can still fail: the model gives up, runs out of time, or refuses the content partway. The generation then reads like this:
{
"id": "gen_9sLq2VbX7mN4kR1tYc8WpE",
"status": "failed",
"reserved_usd": 1.35,
"cost_usd": 0,
"error": { "code": "generation_failed", "message": "The generation failed. Nothing was charged." }
}The code is one of four:
generation_failed: the render did not complete. Submit it again.timeout: the job took too long and was cancelled. Submit it again, perhaps shorter.content_policy: the model refused the content after it started. Reword before you resend.invalid_input: a picture turned out to be unusable during the render.
In every case cost_usd is 0 and the hold went back to your balance the moment the job closed. For an image batch, each output settles on its own: three images can succeed while one fails, and only three are charged. Check each output's status rather than the generation's alone. The rules are laid out in what a failed generation costs.
Content refusals: content_policy or content_filtered
Two codes look alike and come from different places. content_policy means the model's maker turned the request down. Third-party models such as Veo 3.1 and Seedance 2.5 keep their makers' rules whatever your settings are, so rewording or moving to another model are the only ways forward. content_filtered means your own workspace's filter stopped the prompt before anything was held. That filter is on by default and reads the prompt (for a clip edit, its note and targets). An owner or admin aged 18 or older can turn it off in Settings, and Frameport's own models then render without it, while third-party models still apply their makers' rules. The acceptable use policy applies either way.
Neither refusal costs anything. The guide to refused AI video prompts helps you tell which rule you met and how to rephrase within it.
A retry loop that does the right thing
A good retry loop retries only what can succeed on a second try, waits as long as the API asks, and never starts a clip twice. The Idempotency-Key handles the last part: sent again with the same body, it returns the generation the first request made instead of a new one.
import os
import random
import time
import uuid
import requests
API = "https://frameport.ai/v1"
HEADERS = {"Authorization": f"Bearer {os.environ['FRAMEPORT_API_KEY']}"}
RETRY_STATUS = {429, 500, 502, 503, 504} # 502 and 504 can only come from a proxy on the way
class ApiError(Exception):
def __init__(self, status, error):
super().__init__(f"{status} {error['code']}: {error['message']} ({error['request_id']})")
self.status = status
self.code = error["code"]
def backoff(attempt):
return min(60, 2 ** attempt) + random.random()
def submit_video(body, key=None, attempts=6):
key = key or str(uuid.uuid4()) # one key for every try of this clip
for attempt in range(attempts):
try:
res = requests.post(
f"{API}/videos/generations",
headers={**HEADERS, "Idempotency-Key": key},
json=body,
timeout=60,
)
except requests.RequestException:
time.sleep(backoff(attempt)) # it may have arrived: the key makes the retry safe
continue
try:
data = res.json()
except ValueError: # not our JSON: a proxy or a cut connection answered
data = {"error": {"code": f"http_{res.status_code}", "message": res.reason, "request_id": "-"}}
if res.ok:
return data # 202 the first time, 200 when the key replays it
error = data["error"]
if res.status_code not in RETRY_STATUS and error["code"] != "request_in_progress":
raise ApiError(res.status_code, error) # 400, 401, 402, 409 conflict: fix first
wait = res.headers.get("Retry-After")
time.sleep(float(wait) if wait else backoff(attempt))
raise RuntimeError(f"gave up after {attempts} tries (Idempotency-Key {key})")
def wait_for(gen, every=5, timeout=1800):
deadline = time.monotonic() + timeout
while gen["status"] in ("queued", "running"):
if time.monotonic() > deadline:
raise TimeoutError(gen["id"])
time.sleep(every)
gen = requests.get(f"{API}/generations/{gen['id']}", headers=HEADERS, timeout=30).json()
return gen
body = {"model": "seedance-2-5", "prompt": "A tram crosses a snowy bridge at night, wide shot", "duration": 5}
gen = wait_for(submit_video(body))
if gen.get("error") and gen["error"]["code"] in ("generation_failed", "timeout"):
gen = wait_for(submit_video(body)) # a NEW key: the old one would return the failed job
print(gen["status"], gen["cost_usd"])Three choices in that loop matter. A network error is retried with the same key, because you cannot know whether the first request arrived. A 400, 401 or 402 stops at once, since the same call would fail the same way. And a job that failed after the 202 gets a new key: the old one stays bound to the failed generation for 24 hours. The idempotency guide covers the key in depth, and the rate limits guide explains how to stay under the 429s in the first place.
FAQ
What does error 429 mean on an AI video API?
The workspace sent more requests that start work than it may in a minute (rate_limited), or already has 20 generations running (concurrency_limit). Wait for the seconds in the Retry-After header, then send the same request with the same Idempotency-Key.
Is a failed AI video charged?
No. The price is held when you submit and charged only if the clip succeeds. A refused request holds nothing, and a job that fails after it started shows cost_usd at 0 because the hold went back to your balance.
Why do I get 400 invalid_request?
A field is missing, has the wrong type, or asks for something the model does not make, such as a clip length off its grid. The message names the field and lists what the model takes, so read it, fix that field, and send the request again. Each model page lists the values its requests may use.
What should I do with request_id?
Log it with the error. It is in the body of every error and in the X-Request-Id header, and it lets support find your exact call if you need help.
Why does my request return 503?
The model or the service cannot take work for the moment. Nothing was held. Retry after a short, growing delay with the same Idempotency-Key, or move the job to another model in the meantime.