This guide outlines the workflow for using the Swiftia API to automatically generate shorts from a long video and then render them with simple captions.
Prerequisites #
- API Key: You need a Swiftia API key.
- Authentication: All requests must include the header:
Authorization: Bearer YOUR_API_KEY.
Step 1: Create a Generation Job #
First, you need to submit a video to be analyzed. Swiftia will process the video and identify engaging clips (“shorts”).
Endpoint: POST https://app.swiftia.io/api/jobs
Payload:
functionName: Must be set to"VideoShorts".youtubeVideoId: The ID of the YouTube video you want to process (e.g., forhttps://www.youtube.com/watch?v=dQw4w9WgXcQ, the ID isdQw4w9WgXcQ).
Request Example (curl):
curl -X POST https://app.swiftia.io/api/jobs \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"functionName": "VideoShorts",
"youtubeVideoId": "dQw4w9WgXcQ"
}'
Response:
The API will return a JSON object containing a jobId. Save this ID for the next step.
{
"jobId": "abc-123-job-id",
"status": "PROCESSING"
}
Step 2: Poll for Job Completion #
Video processing takes time. You need to check the status of the job periodically until it is complete.
Endpoint: GET https://app.swiftia.io/api/jobs/{jobId}
Request Example:
curl -X GET https://app.swiftia.io/api/jobs/abc-123-job-id \
-H "Authorization: Bearer YOUR_API_KEY"
Response:
When the job is finished, the status will be COMPLETED and the response will include a shorts array. Each item in this array represents a generated short and has a unique id.
{
"id": "abc-123-job-id",
"status": "COMPLETED",
"shorts": [
{
"id": "short-id-1",
"title": "Viral Moment 1",
"start": 10.5,
"end": 45.0
},
{
"id": "short-id-2",
"title": "Funny Clip",
"start": 120.0,
"end": 150.0
}
]
}
Select the id of the short you want to render (e.g., "short-id-1") for the next step.
Step 3: Render the Short (with Simple Captions) #
Now you will create a rendering job. This creates the final MP4 file. To apply “simple captions,” we will define a basic style in the options object.
Endpoint: POST https://app.swiftia.io/api/render
Payload:
id: ThejobIdfrom Step 1.target: Theshort-idfrom Step 2.options: Configuration for captions and layout. We will set a simple white color style.
Request Example:
curl -X POST https://app.swiftia.io/api/render \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"id": "abc-123-job-id",
"target": "short-id-1",
"size": {
"width": 1080,
"height": 1920,
"name": "9:16"
},
"options": {
"maxWordsInPage": 5,
"style": [
{
"property": "color",
"value": "#FFFFFF",
"active": {
"value": "#FFFF00"
}
}
]
}
}'
Note: In the style example above, the text is white (#FFFFFF) and turns yellow (#FFFF00) when active (spoken).
Response:
The API will return a renderId.
{
"renderId": "xyz-789-render-id"
}
Step 4: Get the Final Video #
Poll the render endpoint to get the final video URL.
Endpoint: GET https://app.swiftia.io/api/render/{renderId}
Request Example:
curl -X GET https://app.swiftia.io/api/render/xyz-789-render-id \
-H "Authorization: Bearer YOUR_API_KEY"
Response:
When the rendering is finished, the type will be done and the url field will contain the link to your final video.
{
"type": "done",
"url": "https://storage.swiftia.io/renders/final_video.mp4"
}