Guides

Errors

Failed requests return an HTTP status in the 4xx or 5xx range and the same JSON shape: success is false and error explains why in one sentence you can show to a user.

Format

400 Bad Request
{
    "success": false,
    "error": "Field \"prompt\" is required"
}

Some errors add context: rate_limit on 429, current_plan on 403, alternatives on 410.

Status codes

StatusMeaningWhat to do
200Success.Read video_url.
400A field is missing or invalid.Fix the request; retrying the same body will fail again.
401No key, a malformed header or an unknown key.Check the Authorization: Bearer header.
403Not on the API plan, or the video belongs to someone else.Upgrade the plan or check the video_id.
404No video with this video_id.Check the id.
405Wrong method.POST for generations, GET for status.
410sora2 was retired.Use an id from alternatives.
429Rate limit reached.Wait Retry-After seconds.
500The generation could not be completed.Read error: see the messages below.

Messages you can receive

errorStatusMeaning
Missing or invalid Authorization header. Use: Bearer YOUR_API_KEY401Header missing or without Bearer.
Invalid API key401Regenerated or unknown key.
API access requires the API plan. Please upgrade your subscription.403The account is on another plan.
Field "prompt" is required400Text to video without a prompt.
Prompt cannot exceed 7000 characters400Shorten the prompt.
Field "image_url" is required · Invalid image_url format400Image to video without a valid URL.
video_id parameter is required400Status call without an id.
Rate limit exceeded. …42915 generations in the last 30 minutes.
You have reached the generation limit of your plan for this month. …500No credits left until the monthly reset or an upgrade.
This prompt or image was blocked by the content filter. …500Rephrase the prompt or use another image.
High demand right now. Please try again in a few minutes.500Temporary capacity limit. Retry later.
Something went wrong on our side and this generation could not be completed. …500Model or network failure. Retry once, then contact us with the time of the request.

Handling errors

Branch on the status, show error to the user, and retry only what can succeed later: 429 and the temporary 500s.

import os, requests

def generate(prompt: str) -> str:
    resp = requests.post(
        "https://lannevideo.com/api/v1/text-to-video",
        headers={"Authorization": f"Bearer {os.environ['NB_API_KEY']}"},
        json={"prompt": prompt},
        timeout=300,
    )
    data = resp.json()
    if resp.ok:
        return data["video_url"]
    if resp.status_code in (401, 403):
        raise PermissionError(data["error"])     # fix the key or the plan
    if resp.status_code == 429:
        raise RuntimeError(f"Retry in {resp.headers.get('Retry-After')} s")
    raise RuntimeError(data["error"])            # 400: fix the request, 500: show and maybe retry