aigens

API documentation

Everything you do on the aigens website can be done from a script: write a script from an idea, create episodes, generate character images, render, download videos, and make affiliate videos. Limits are the same as on the website; a few actions are priced differently, see Pricing for API calls.

Contents
  1. 1. Base URL and keys
  2. 2. General conventions
  3. 3. Pricing for API calls
  4. 4. Making an episode, step by step
  5. 5. Affiliate videos
  6. 6. Safe retries
  7. 7. Callbacks to your server
  8. 8. Common endpoints
  9. 9. Limits
  10. 10. Error codes

1. Base URL and keys

Base URL: https://aigens.app. Create a key on the API page in the studio, then send it with every request in the Authorization header:

curl https://aigens.app/api/me \
  -H "Authorization: Bearer aig_YOUR_KEY"
  • A key is shown only once, when it is created. If you lose it, revoke it and create a new one; each account can have up to 5 keys.
  • A key can do everything the account can, including spending spirit stones. Never put a key in code that runs in a browser or in a public repository.
  • Keys cannot be used to create or revoke keys.

2. General conventions

  • Requests and responses are JSON. Files (images, videos) are not sent with the request: get a link from POST /api/uploads, PUT the file straight to storage at that link, then send the key you got. Images up to 5 MB, videos up to 100 MB.
  • Errors return an HTTP status of 400 or above with { "error": "human-readable message", "code": "CODE" }. The message follows your Accept-Language header (Vietnamese by default). The code field is present when the error is one of the predefined kinds.
  • Common statuses: 401 wrong or revoked key; 402 not enough spirit stones; 409 the action can't be done right now (a scene is rendering, a character has no image: CAST_NOT_READY); 422 the script doesn't match the format, with a list of issues per scene.
  • Rate limits per account: reads (GET) 120 per minute, writes (POST, PATCH, DELETE) 20 per minute. Going over returns 429 with "code": "RATE_LIMITED" and a Retry-After header (seconds to wait). Sending a wrong key many times in a row blocks you for one minute.
  • Four actions spend spirit stones: writing a script from an idea, generating a character image, sending scenes to render, and sending an affiliate video. Failed runs are refunded automatically.
  • Rendering runs in the background. Polling the status every 5 to 15 seconds is enough, or let the system notify your server when it is done (section 7). When retrying a call that creates a job, send an Idempotency-Key so you are never charged twice (section 6).

3. Pricing for API calls

When you call with an API key, content-generating actions have their own prices: rendering scenes and affiliate videos cost the website price times 100%, rounded up. First-time offers (your first video of each type: regular videos and each affiliate video type) are only available on the website; API calls don't get the discount and don't use it up either.

ActionOn the websiteVia the API
Write a script from an idea (each time)free2 spirit stones
Generate a character image (each image, including regenerations)free1 spirit stones
Render one scene (including redos)2 spirit stones2 spirit stones
One affiliate video10 spirit stones10 spirit stones
One affiliate video (Standard quality)5 spirit stones5 spirit stones
Create episodes, stitching, reading datafreefree

Current prices are always in GET /api/me, under pricing.api. The quote in GET /api/episodes/{id} already uses API prices when you call with a key. Every charge returns charged; the spirit stone ledger adds "(API)". A failed script draft is refunded right away.

4. Making an episode, step by step

The six steps below match the steps you click through on the website. A complete, runnable version is in the Python example at the top of this page.

Step 1. The system writes a script from your idea (free)

curl -X POST https://aigens.app/api/episodes/draft \
  -H "Authorization: Bearer $AIGENS_KEY" -H "Content-Type: application/json" \
  -d '{"idea": "The Tortoise and the Hare race a second time, with a surprise ending.", "sceneCount": 5, "voiceGender": "female"}'

# Returns: { "json": "<JSON prompt string>", "issues": [] }

A JSON prompt has the shape { title, style, characters: [{ key, name, description }], scenes: [{ prompt, voice }] } (for a no-voice episode add no_voice: true and leave out voice). You can edit it before creating the episode, or write the whole JSON yourself and skip this step. Whenever a character appears in a scene, that scene's prompt must mention the character's exact key.

Step 2. Create the episode (free)

curl -X POST https://aigens.app/api/episodes \
  -H "Authorization: Bearer $AIGENS_KEY" -H "Content-Type: application/json" \
  -d '{"json": "<JSON prompt string from step 1>", "aspect": "9:16", "voiceGender": "female", "captions": true}'

# Returns: { "id": "<episode id>", "imagesQueued": 2, "charged": 2 }

Step 3. Character images (costs spirit stones)

Read the episode to get its characters, request an image for each one (each image costs spirit stones, regenerations included; a failed image is refunded; with too few spirit stones you get 402 and nothing is queued), wait until the status becomes pending_review, then approve it. If you have your own image, upload it instead of generating one; uploaded images are approved right away.

curl https://aigens.app/api/episodes/$EPISODE -H "Authorization: Bearer $AIGENS_KEY"
# episode.cast: [{ "id": "...", "key": "character_tho", "status": "no_image" }, ...]

curl -X POST https://aigens.app/api/characters/episode/$CHARACTER/image   -H "Authorization: Bearer $AIGENS_KEY"
curl -X POST https://aigens.app/api/characters/episode/$CHARACTER/approve -H "Authorization: Bearer $AIGENS_KEY"

# Or use your own image: get a link, upload the image straight to storage, then attach it to the character.
curl -X POST https://aigens.app/api/uploads -H "Authorization: Bearer $AIGENS_KEY" -H "Content-Type: application/json" \
  -d '{"kind": "character-image", "type": "image/jpeg", "size": '$(wc -c < hare.jpg)', "scope": "episode", "characterId": "'$CHARACTER'"}'
# Returns: { "key": "characters/.../upload-....jpg", "url": "https://...", "method": "PUT", "headers": { "content-type": "image/jpeg" } }
curl -X PUT "$URL" -H "content-type: image/jpeg" --data-binary @hare.jpg
curl -X POST https://aigens.app/api/characters/episode/$CHARACTER/upload -H "Authorization: Bearer $AIGENS_KEY" \
  -H "Content-Type: application/json" -d '{"key": "'$KEY'"}'

Step 4. Render (spends spirit stones)

curl -X POST https://aigens.app/api/episodes/$EPISODE/render \
  -H "Authorization: Bearer $AIGENS_KEY" -H "Content-Type: application/json" -d '{}'

# Returns: { "charged": 50, "scenes": 5, "balance": 450 }

The amount to be charged is in quote.total when you read the episode. To redo a few scenes, send {"sceneIds": ["<scene id>"]}.

Step 5. Wait for rendering and stitching

Read the episode again until episode.status is done. In automatic stitch mode, the system stitches as soon as the last scene is finished.

waiting_castSome characters don't have an approved image yet
validatedReady to render
renderingRendering scenes. If no rendering accounts are available, the episode stays in this state until one frees up, without an error
stitchingAll scenes are done; stitching
doneThe full episode video is ready
partialSome scenes failed. Failed scenes were refunded; resend them with sceneIds

Step 6. Download the video

curl -L -o episode.mp4 https://aigens.app/api/episodes/$EPISODE/download -H "Authorization: Bearer $AIGENS_KEY"

Videos are kept for a limited time (see keepDays in /api/me). After that the video is deleted; the script and characters stay.

6. Safe retries

On a flaky network, retrying a call can create the job twice and charge you twice. The two endpoints that create paid jobs, POST /api/episodes/{id}/render and POST /api/trends, take an Idempotency-Key header (or a clientToken field in the JSON or form body): send the same key again and you get the very same result back, with no new job and no new charge.

KEY=$(uuidgen)   # one key per new job; reuse this exact key when you retry that job
curl -X POST https://aigens.app/api/episodes/$EPISODE/render -H "Authorization: Bearer $AIGENS_KEY" \
  -H "Content-Type: application/json" -H "Idempotency-Key: $KEY" -d '{}'
# Returns: { "charged": 50, "scenes": 10, "balance": 950 }
# Same key again: the same body, with the header "Idempotent-Replayed: true", and no new charge
  • A key is 1 to 255 printable characters (no spaces, no accented letters). A UUID works well. Keys are kept for 24 hours per account.
  • Two calls with the same key at the same moment: only one creates the job; the other waits and gets its result.
  • A failed call (not enough stones, invalid script…) does not keep the key: fix the problem and retry with the same key for a real new attempt.
  • The same key on another endpoint or with different content: 422 IDEMPOTENCY_KEY_REUSED. A header and clientToken that differ, or a malformed key: 400 BAD_IDEMPOTENCY_KEY.

7. Callbacks to your server

Instead of polling, let the system notify your server when an episode or affiliate video finishes or fails. Set a callback URL (https) for a key on the API keys page (press Callbacks); the first time you set one, a signing secret whsec_... is created and shown only once. Every episode and affiliate video sent with that key is reported to that URL. To report one job somewhere else, add callbackUrl to the call that creates it (still signed with that key's secret).

curl -X POST https://aigens.app/api/trends -H "Authorization: Bearer $AIGENS_KEY" -H "Content-Type: application/json" \
  -d '{"characterKey": "'$IMAGE_KEY'", "url": "'$LINK'", "callbackUrl": "https://your-server.example.com/aigens"}'

Events (the event field):

episode.doneThe episode's final video is stitched.
episode.partialNo scene is still rendering but some failed (failed scenes were refunded). Re-render them or fix the script.
episode.awaiting_reviewReview mode: all scenes are rendered and wait for your approval.
episode.stitch_failedStitching the final video failed. Call POST /api/episodes/{id}/stitch again.
trend.doneThe affiliate video is ready; download it at GET /api/trends/{id}/video.
trend.failedThe affiliate video failed (refunded under the refund rules). Details at GET /api/trends.

Each notification is a JSON POST:

POST https://your-server.example.com/aigens
Content-Type: application/json
X-Webhook-Id: 7d0c…            # unique per notification, kept on retries: use it to drop duplicates
X-Webhook-Event: trend.done
X-Webhook-Timestamp: 1792944765
X-Webhook-Signature: sha256=5f2b…

{ "id": "7d0c…", "event": "trend.done", "createdAt": "2026-10-25T09:00:00.000Z",
  "data": { "trendId": "…", "status": "done", "title": "…", "errorKind": null } }
# episode events: "data": { "episodeId": "…", "status": "done", "title": "…", "scenes": { "total": 8, "done": 8, "failed": 0 } }

Check the signature before trusting a notification: it is an HMAC-SHA256 with the signing secret over the string <timestamp>.<raw body>, in hex.

// Node.js (Express): use the raw body, don't parse and re-stringify it
import crypto from "node:crypto";
app.post("/aigens", express.raw({ type: "application/json" }), (req, res) => {
  const ts = req.get("X-Webhook-Timestamp");
  const body = req.body.toString("utf8");
  const want = "sha256=" + crypto.createHmac("sha256", process.env.AIGENS_WEBHOOK_SECRET).update(ts + "." + body).digest("hex");
  const got = req.get("X-Webhook-Signature") ?? "";
  const fresh = Math.abs(Date.now() / 1000 - Number(ts)) < 300; // drop notifications older than 5 minutes
  if (!fresh || got.length !== want.length || !crypto.timingSafeEqual(Buffer.from(got), Buffer.from(want))) {
    return res.status(401).end();
  }
  const event = JSON.parse(body);
  // ... handle event.event, event.data; remember event.id to drop duplicates
  res.status(200).end();
});
# Python (Flask)
import hashlib, hmac, os, time
from flask import Flask, request, abort
app = Flask(__name__)

@app.post("/aigens")
def aigens():
    ts = request.headers.get("X-Webhook-Timestamp", "")
    body = request.get_data()  # raw bytes
    want = "sha256=" + hmac.new(os.environ["AIGENS_WEBHOOK_SECRET"].encode(), ts.encode() + b"." + body, hashlib.sha256).hexdigest()
    if abs(time.time() - int(ts or 0)) > 300 or not hmac.compare_digest(want, request.headers.get("X-Webhook-Signature", "")):
        abort(401)
    event = request.get_json()
    # ... handle event["event"], event["data"]
    return "", 200
  • Answer with a 2xx within 10 seconds and the notification counts as delivered. Any other code, a timeout or a redirect (3xx) is retried after 1, 2, 5, 10, 30, 60 and then 120 minutes; after 8 failed tries (about 4 hours) it is dropped. You can still read the job's status with GET as usual.
  • You may get a notification twice: drop any id you have already seen. Arrival order may differ from the order things happened; a notification shows the state when it was sent, so read it again with GET if you need the latest.
  • Notifications are signed with the key's current signing secret at send time. Creating a new secret retires the old one at once. Revoking the API key stops all of its notifications.
  • The URL must be https and must not point to a private network (a hostname that resolves to a private address at send time is blocked too). The Send a test button on the API keys page sends a signed ping right away so you can check your server.

8. Common endpoints

GET/api/meAccount, spirit stone balance, current prices and limits

Cost: free.

GET/api/voicesReader voices you can pick for an episode in one video language (language, e.g. ?language=en-US; vi-VN by default): id, name, gender, language, style, sampleUrl (sample clip link, may be null); plus languages: every video language that has voices

Cost: free.

POST/api/episodes/draftThe system writes a script (JSON prompt) from an idea: idea (up to 2,000 characters), sceneCount, language (the video language: the title, character names and voiceover are written in it; defaults to the voice's language, then vi-VN), voiceId or voiceGender, projectId. SPENDS SPIRIT STONES when called with an API key (refunded if no script could be written); returns charged

Cost: 2 spirit stones per call, refunded if no script could be written.

POST/api/episodesCreate an episode from a JSON prompt: json, idea, aspect (9:16 or 16:9), language (the video language, must match the voice's language; defaults to the voice's language, then vi-VN), voiceId (the id of a voice from GET /api/voices) or voiceGender (male by default, or female: the first voice of that gender in the video language), speed (1, 1.1 by default, 1.2, 1.25, 1.5), outputResolution (1080p by default, or 720p: the final video's resolution; stitching 1080p takes longer), quality (high: High quality, scenes rendered at 720p, the regular scene price; normal: Standard quality, scenes rendered at 360p, a lower per-scene price, queued after other jobs; omitted: the regular scene price as before; fixed when the episode is created), captions, useLogo (default true: puts a logo over the Gemini mark in the bottom-right corner of the final video: the project's own logo from PUT /api/projects/{id}/episode-logo, otherwise the logo you upload at PUT /api/me/episode-logo, otherwise the aigens logo; false for no logo), noVoice (true: a no-voice episode, also turned on by no_voice: true in the JSON: scenes need no voice and any voice text is ignored, there is no voice or captions and speed is always 1, so voiceId, voiceGender, captions and speed are ignored; each scene keeps the clip's full length and its sound; set at creation and cannot be changed later), stitchMode (auto or review), renderMode (parallel by default: every scene renders at once; sequential: one at a time, each scene starts from the last frame of the one before and every scene is reviewed), projectId, autoCharacterImages (true by default: queue image generation for characters without an image; false if you upload your own; each generated image costs spirit stones as in POST /api/characters/episode/{id}/image, and characters you can't afford are skipped). Creating the episode is free. Returns id, imagesQueued (images queued) and charged (spirit stones charged for those images, 0 on the web)

Cost: creating the episode is free; with autoCharacterImages on, 1 spirit stones per queued image (refunded if an image fails).

GET/api/episodesList episodes: limit, offset, projectId or loose=1

Cost: free.

GET/api/episodes/{id}One episode: status, characters, each scene, plus a price quote (quote)

Cost: free.

GET/api/episodes/{id}/statusCompact status for polling while you wait: status, version, finalReady, and the status of each scene (scenes) and character (cast). Send If-None-Match: "<version>" and you get a 304 with no body while nothing has changed. Much lighter than loading the whole episode: poll this, and call GET /api/episodes/{id} only when it changes

Cost: free.

PATCH/api/episodes/{id}Change the title, style, aspect ratio, captions, stitch mode, scene order (renderMode: parallel or sequential), speed (speed), final video resolution (outputResolution), reader voice (voiceId or voiceGender, in the episode's video language; locked once a scene has been sent to render). On a no-voice episode, turning captions on, a speed other than 1 or changing the voice returns 409 NO_VOICE_LOCKED

Cost: free.

DELETE/api/episodes/{id}Delete the episode

Cost: free.

POST/api/characters/episode/{id}/imageRequest an image for one of the episode's characters. COSTS SPIRIT STONES when called with an API key (refunded if the image fails), with a daily regeneration quota. Returns jobId and charged (0 on the web)

Cost: 1 spirit stones per image (regenerations included), charged when requested and refunded if the image fails.

POST/api/characters/episode/{id}/uploadAttach your own image to a character: key (from POST /api/uploads, kind character-image). Approved right away

Cost: free.

POST/api/characters/episode/{id}/approveApprove a character image

Cost: free.

PATCH/api/scenes/{id}Edit the image prompt or voiceover of a scene that hasn't been sent to render

Cost: free.

POST/api/episodes/{id}/renderRender and SPEND SPIRIT STONES. No body: every draft scene (one-at-a-time episodes: only the next draft scene, once the scene before it is approved; approving a scene then sends the next one and spends its stones). sceneIds: redo those scenes

Cost: 2 spirit stones per scene (redos included), charged when you send it to render and refunded for a scene that fails.

POST/api/episodes/{id}/stitchStitch, or re-stitch, into one video. Free

Cost: free.

GET/api/scenes/{id}/videoRedirects to a scene's video; add ?download=1 to download it

Cost: free.

GET/api/episodes/{id}/downloadRedirects to the download link of the full episode video

Cost: free.

GET/api/trendsYour affiliate videos, your balance, and terms: the next run's price (cost is the High quality price, costs the price of each quality, high/normal) and the number of seconds used

Cost: free.

POST/api/uploadsGet a link to upload one file straight to storage: kind (trend-video, trend-character, character-image with scope and characterId), type, size. Returns key, url, method, headers

Cost: free.

POST/api/trendsSend an affiliate video and SPEND SPIRIT STONES: kind (video type, swap_character by default: replace the character), characterKey (image) plus videoKey (file) or url (TikTok, YouTube Shorts or Facebook Reels link), title, aspect (source by default, 9:16, 16:9, 1:1), keepAudio (true by default), quality (high by default: High quality, rendered at 720p; normal: Standard quality, rendered at 360p then upscaled, a lower price, queued after other jobs). Keys come from POST /api/uploads

Cost: 10 spirit stones per High quality video, 5 per Standard quality video, charged when you send it and refunded if it fails.

GET/api/trends/{id}/videoRedirects to the result video; add ?download=1 to download it

Cost: free.

GET/api/walletBalance and spirit stone ledger

Cost: free.

9. Limits

Rate limits apply only to calls with an API key and are counted per minute for each account (all keys of an account share them):

  • Reads (GET): 120 per minute.
  • Writes (POST, PATCH, DELETE): 20 per minute.
  • Sending a wrong key 20 times within a minute from the same IP address blocks every key from that IP until the minute is over.
  • Over the limit: HTTP 429, { "code": "RATE_LIMITED", "retryAfter": 37 }, with the headers Retry-After, X-RateLimit-Limit, X-RateLimit-Remaining.

Content limits currently in effect (the same as on the website; the latest numbers are always in GET /api/me, under limits):

Scenes per episodeup to 30
Length of each scene10 to 10 seconds
Voiceover per scene15 to 200 words; voices that aren't Vietnamese read slower, so their maximum is lower (162 words for English); a no-voice episode (no_voice) needs no voiceover
Image prompt per sceneup to 2000 characters
Prompt sent per sceneup to 4000 characters, including the style and the descriptions of the characters in the scene
Charactersup to 20 per episode, 5 per scene
Regenerating character images30 times a day for the whole account (the first image of a character doesn't count)
Uploaded character imagesup to 5 MB
Affiliate videosuses the first 30 seconds; source videos up to 60 seconds and 100 MB; character images up to 5 MB
Video retentionstitched videos are kept 7 days; scenes of an unstitched episode are kept 7 days

10. Error codes

Every error returns JSON { "error": "human-readable message", "code": "CODE" }. Rely on code when it is present to handle errors in your script; the wording in error may change.

HTTP statuses

400The data sent is wrong or missing (parameters, file too large, wrong format).
401Missing, wrong or revoked key.
402Not enough spirit stones for this action.
403Not allowed: the account is blocked, or the action is only available when logged in on the website (managing API keys).
404Not found, or it doesn't belong to your account.
409Can't be done right now because of the current state (a scene is rendering, a character has no image, the episode is stitching…). See code.
422The script doesn't match the format or exceeds a limit, with a list of issues per scene.
429Over the rate limit (RATE_LIMITED) or out of character image regenerations for today (DAILY_LIMIT).
500Server error. Try again later; if it keeps happening, email contact@aigens.app.
503The server isn't ready yet.

Values of code

BAD_IMAGE_PATH400Invalid image file.
BAD_OUTPUT_RESOLUTION400Video resolution must be 720p or 1080p.
BAD_QUALITY400Video quality must be high or normal.
BAD_RENDER_MODE400Invalid scene order: use parallel or one at a time.
BAD_SPEED400Video speed must be between 0.5x and 2x.
BAD_TREND_ASPECT400Invalid affiliate video frame.
BAD_TREND_KIND400Invalid affiliate video type.
CHARACTER_KEY_OVERLAP400This character key is part of (or contains) another key. Rename it so they can't be confused.
DUPLICATE_SCENE400The scene list contains duplicates.
LANGUAGE_NOT_AVAILABLE400There is no voice for this video language yet.
NO_SCENES400No scenes selected to send.
ORDER_MISMATCH400The episode list doesn't match the project.
PROMPT_REQUIRED400The scene has no prompt yet.
VOICE_LANGUAGE_MISMATCH400The voice is not in the video's language.
VOICE_NOT_FOUND400This voice does not exist or is turned off.
INSUFFICIENT_BALANCE402Not enough spirit stones.
BLOCKED403This account is locked.
CHARACTER_NOT_FOUND404Character not found.
EPISODE_NOT_FOUND404Episode not found.
IMAGE_NOT_FOUND404This character image was not found.
PROFILE_NOT_FOUND404Account not found.
PROJECT_NOT_FOUND404Project not found.
SCENE_NOT_FOUND404Scene not found.
TREND_NOT_FOUND404Video not found.
ASPECT_LOCKED409The aspect ratio is locked once a scene has been sent to render.
CAST_LOCKED409An episode using this character is creating scenes or stitching, so its image can't be changed yet. Wait for it to finish, then try again.
CAST_NOT_READY409A character in this scene has no approved image. Generate or upload an image and approve it before creating the video.
CHARACTER_BUSY409The character image is being generated.
CHARACTER_CONFLICT409The episode and the project have different images for the same character. Choose which one to keep.
CHARACTER_EXISTS409This character key already exists.
CHARACTER_LIMIT409The episode already has the maximum number of characters.
CHARACTER_NOT_REVIEWABLE409The character has no image waiting for review.
JOB_NOT_CANCELABLE409This job has already finished, failed or been canceled.
JOB_STILL_RUNNING409An AI server is still working on this job (it is still reporting in), so it can't be canceled.
LAST_SCENE409An episode must keep at least one scene.
PROJECT_BUSY409The project still has work running (rendering scenes, drawing characters or stitching). Wait for it to finish, then delete.
QUALITY_LOCKED409Video quality is locked once the episode has character images or scenes sent for generation.
SCENE_BUSY409The scene is queued or rendering, so it can't be changed right now.
SCENE_NO_CANDIDATE409This scene has no new version waiting to be picked.
SCENE_NOT_REVIEWABLE409This scene is not ready for review yet.
SCENES_NOT_APPROVED409Some scenes haven't been approved.
SCENES_NOT_CHOSEN409Some re-rendered scenes still need a version picked. Pick the previous or the new version of each scene before stitching.
SCENES_NOT_READY409Some scenes haven't finished rendering.
SEQUENCE_NEXT_BUSY409The next scene is being made from this scene's last frame. Wait for it to finish before redoing this scene.
SEQUENCE_PREVIOUS_NOT_APPROVED409This episode is made one scene at a time: approve the scene before it (and pick a version if you just redid it) first, because this scene starts from that scene's last frame.
STITCH_BUSY409The episode is being stitched.
STITCH_UP_TO_DATE409The current stitched video is already up to date.
TREND_BUSY409The video is being rendered and can't be deleted yet.
VOICE_LOCKED409The voice is locked once a scene has been sent to render.
IDEMPOTENCY_KEY_REUSED422This idempotency key was already used for a different request (another route or different content). Use a new key for each new request.
DAILY_LIMIT429You've used all of today's character image regenerations.
FIRST_IMAGE_LIMIT429You've reached today's limit of free images for new characters. You can draw more tomorrow, or upload character images.
RATE_LIMITED429The API key's rate limit was exceeded. Wait the number of seconds in retryAfter (or the Retry-After header), then call again.

Video creation under maintenance