Quick start: your first Video
These curl steps go from a Description to a downloaded Video. Each paid step is quoted first, and starting it charges exactly the quoted price. Set the base URL and your key once:
export CASTLAB_API=https://castlab.ai/api/public/v1
export CASTLAB_KEY=cl_<prefix>_<secret>1. Check the Description
Every Description is checked for prohibited content first. Keep the returned
id; ablockverdict can't be quoted.curl -X POST "$CASTLAB_API/checks/text" -H "Authorization: Bearer $CASTLAB_KEY" -H "Content-Type: application/json" \ -d '{"text": "A cheerful red-haired barista in a green apron"}' # → {"id": "<check_result_id>", "verdict": "allow", ...}2. Quote the Variant Grid
Send the same Description with the check's
id. The answer holdsquote_idandpricein Credits; a quote is single use and expires atexpires_at.curl -X POST "$CASTLAB_API/quotes" -H "Authorization: Bearer $CASTLAB_KEY" -H "Content-Type: application/json" \ -d '{"kind": "variant_grid", "description": "A cheerful red-haired barista in a green apron", "check_result_id": "<check_result_id>"}' # → {"quote_id": "<grid_quote_id>", "price": <credits>, "expires_at": "..."}3. Start the Variant Grid
Pass the quote with a new
Idempotency-Keyfor each attempt: a repeat with the same key returns the first Generation and charges nothing. Keepgeneration_id.curl -X POST "$CASTLAB_API/variant-grids" -H "Authorization: Bearer $CASTLAB_KEY" -H "Content-Type: application/json" \ -H "Idempotency-Key: $(uuidgen)" \ -d '{"quote_id": "<grid_quote_id>", "description": "A cheerful red-haired barista in a green apron", "check_result_id": "<check_result_id>"}' # → {"generation_id": "<grid_generation_id>"}4. Wait for the 4 Variants
Poll every few seconds until
stateissucceeded,failedortimed_out; a Generation that doesn't succeed charges nothing. Keep theidof the Variant you like.curl "$CASTLAB_API/variant-grids/<grid_generation_id>" -H "Authorization: Bearer $CASTLAB_KEY" # → {"state": "succeeded", "variants": [{"id": "<variant_id>", "url": "..."}, ...]}5. Approve a Variant as your Character
Approval is free, and so are the Character's 3 Angles, which start at once. Keep the Character's
id.curl -X POST "$CASTLAB_API/characters" -H "Authorization: Bearer $CASTLAB_KEY" -H "Content-Type: application/json" \ -d '{"variant_id": "<variant_id>", "language": "en"}' # → {"id": "<character_id>", "name": "...", "angles_state": "submitted", ...}6. Pick a trend clip
List the Library and keep the
idof a clip whosemax_output_sis set (a clip too long to follow has it null), then pickduration_sbetween itsmin_output_sandmax_output_s. You can also upload your own clip withPOST /reference-clips.curl "$CASTLAB_API/library/clips" -H "Authorization: Bearer $CASTLAB_KEY" # → [{"id": "<clip_id>", "title": "...", "min_output_s": 3, "max_output_s": 10, ...}]7. Quote the Video
Quote your Character, the clip and the seconds of output.
curl -X POST "$CASTLAB_API/quotes" -H "Authorization: Bearer $CASTLAB_KEY" -H "Content-Type: application/json" \ -d '{"kind": "video", "character_id": "<character_id>", "reference_clip_id": "<clip_id>", "duration_s": 5}' # → {"quote_id": "<video_quote_id>", "price": <credits>, "expires_at": "..."}8. Start the Video
Send exactly the quoted inputs with a new
Idempotency-Key. Keepgeneration_id.curl -X POST "$CASTLAB_API/videos" -H "Authorization: Bearer $CASTLAB_KEY" -H "Content-Type: application/json" \ -H "Idempotency-Key: $(uuidgen)" \ -d '{"quote_id": "<video_quote_id>", "character_id": "<character_id>", "reference_clip_id": "<clip_id>", "duration_s": 5}' # → {"generation_id": "<video_generation_id>"}9. Wait for the Video
Poll until
stateis terminal, or set a webhook for the key and wait for its POST instead.curl "$CASTLAB_API/videos/<video_generation_id>" -H "Authorization: Bearer $CASTLAB_KEY" # → {"state": "succeeded", "video": {"id": "...", "url": "...", "duration_s": 5, ...}, ...}10. Download it
The answer holds a short-lived MP4 URL; fetch it right away.
curl "$CASTLAB_API/videos/<video_generation_id>/download" -H "Authorization: Bearer $CASTLAB_KEY" # → {"url": "<mp4_url>", "ai_label_reminder": "..."} curl -o video.mp4 "<mp4_url>"
Label the Video as AI-generated wherever you post it. The download answer's ai_label_reminder says so too.