This guide walks through clip_generator.py, a script in the clip-api-examples repo that uses the Clip API to extract short, captioned segments from a longer video. You provide a video source, either a YouTube URL or a local MP4 file, and the script handles the rest: downloading or uploading the video, analyzing it, and rendering a new clip based on your instructions. The example in this guide uses a YouTube URL to keep the setup simple.
The full source code is available at github.com/reka-ai/clip-api-examples.
Prerequisites
Clone the repository and install dependencies:
git clone https://github.com/reka-ai/clip-api-examples
cd clip-api-examples/python
pip install -r requirements.txt
Then export your API key:
export REKA_API_KEY=your_key_here
If you don't have a key yet, get one here. Free credits renew every month.
Running the Script
From the python/ folder, run:
python clip_generator.py
The script prompts you for a YouTube URL. Paste it in, and the job starts immediately.
The Job Lifecycle
Once submitted, the job moves through several statuses printed to your terminal: queued, processing, then completed. This works because the script uses stream=True in its HTTP request, which keeps the connection open and lets the script poll in a loop until the job finishes. If you prefer, you can remove stream=True and instead make one call to create the job, then a separate polling call to check its status.
Customizing the Payload
The heart of the script is the create_clip function, which builds a payload for the API:
payload = {
"video_url": url,
"prompt": "create an engaging video clip highlighting the best moments",
"template": "moment",
"num_generations": 1,
"generation_config": {
"aspect_ratio": "9:16",
"subtitles": True,
"min_duration_seconds": 10,
"max_duration_seconds": 30
}
}
Each field is customizable:
-
prompt: Plain-language instruction. Examples: "the funniest moments", "the part where I did the demo". Treat it like a brief to an editor. -
template: Controls the overall clip style."moment"is one option; the repo includes others. -
num_generations: Request multiple clip variations in one job, useful for comparing different cuts. -
min_duration_seconds/max_duration_seconds: Keep these short during development for faster turnaround. -
subtitles: Set toTrueto burn captions into the video,Falseto skip them. -
aspect_ratio:"9:16"for TikTok/Reels,"1:1"for square, or keep the original.
The Output
When the job completes, the API returns a generated title, a description of the clip, and suggested hashtags. The video itself is already trimmed and has captions burned in. The demo in the video processed an 18-minute horizontal talk (no captions) into a 25-second vertical clip with orange subtitles.
Clone the repo, adjust the payload to fit your content, and happy clipping.



Top comments (0)