Generate social clips with Grok and Ittybit

View Markdown

You have an hour-long podcast, livestream, or webinar. Somewhere inside are three or four moments that would blow up on social. Grok finds them via function calling, Ittybit cuts and transcodes each one. No timeline scrubbing, no manual exports.

Define the tool

Give Grok a create_clip function it can call whenever it spots a shareable moment.

import OpenAI from "openai";

const xai = new OpenAI({
apiKey: process.env.XAI_API_KEY,
baseURL: "https://api.x.ai/v1",
});

const tools: OpenAI.Chat.Completions.ChatCompletionTool[] = [
{
type: "function",
function: {
name: "create_clip",
description:
"Cut a clip from the source video between the given timestamps",
parameters: {
type: "object",
properties: {
title: { type: "string", description: "Short, punchy clip title" },
start: { type: "number", description: "Start time in seconds" },
end: { type: "number", description: "End time in seconds" },
},
required: ["title", "start", "end"],
},
},
},
];
from openai import OpenAI

xai = OpenAI(
    api_key=os.environ["XAI_API_KEY"],
    base_url="https://api.x.ai/v1",
)

tools = [
    {
        "type": "function",
        "function": {
            "name": "create_clip",
            "description": "Cut a clip from the source video between the given timestamps",
            "parameters": {
                "type": "object",
                "properties": {
                    "title": {"type": "string", "description": "Short, punchy clip title"},
                    "start": {"type": "number", "description": "Start time in seconds"},
                    "end": {"type": "number", "description": "End time in seconds"},
                },
                "required": ["title", "start", "end"],
            },
        },
    }
]

Ask Grok to find the moments

Send the transcript (or a description) and let Grok call create_clip for each highlight.

const transcript = await getTranscript(videoId); // your transcript source

const response = await xai.chat.completions.create({
model: "grok-3",
tools,
messages: [
{
role: "system",
content:
"You are a social media producer. Analyze the transcript and call create_clip for each moment that would perform well as a standalone short-form clip. Aim for 30-90 second segments.",
},
{
role: "user",
content: transcript,
},
],
});
transcript = get_transcript(video_id)  # your transcript source

response = xai.chat.completions.create(
    model="grok-3",
    tools=tools,
    messages=[
        {
            "role": "system",
            "content": "You are a social media producer. Analyze the transcript and call create_clip for each moment that would perform well as a standalone short-form clip. Aim for 30-90 second segments.",
        },
        {
            "role": "user",
            "content": transcript,
        },
    ],
)

Dispatch each clip to Ittybit

Loop through Grokโ€™s tool calls and fire off an Ittybit task for each one. Every task trims the source video and transcodes it to a social-ready format.

const VIDEO_URL = "https://your-bucket.s3.amazonaws.com/episode-42.mp4";

const toolCalls = response.choices[0].message.tool_calls ?? [];

const tasks = await Promise.all(
toolCalls
.filter((call) => call.function.name === "create_clip")
.map(async (call) => {
const { title, start, end } = JSON.parse(call.function.arguments);

      const res = await fetch("https://api.ittybit.com/jobs", {
        method: "POST",
        headers: {
          Authorization: `Bearer ${process.env.ITTYBIT_API_KEY}`,
          "Content-Type": "application/json",
        },
        body: JSON.stringify({
          input: VIDEO_URL,
          kind: "video",
          options: {
            start,
            end,
            format: "mp4",
            width: 1080,
            height: 1920,
            quality: "high",
          },
          metadata: { title },
        }),
      });

      return res.json();
    })

);

console.log(`Created ${tasks.length} clips`);
import requests

VIDEO_URL = "https://your-bucket.s3.amazonaws.com/episode-42.mp4"

tool_calls = response.choices[0].message.tool_calls or []

tasks = []
for call in tool_calls:
    if call.function.name != "create_clip":
        continue

    args = json.loads(call.function.arguments)

    res = requests.post(
        "https://api.ittybit.com/jobs",
        headers={"Authorization": f"Bearer {os.environ['ITTYBIT_API_KEY']}"},
        json={
            "input": VIDEO_URL,
            "kind": "video",
            "options": {
                "start": args["start"],
                "end": args["end"],
                "format": "mp4",
                "width": 1080,
                "height": 1920,
                "quality": "high",
            },
            "metadata": {"title": args["title"]},
        },
    )
    tasks.append(res.json())

print(f"Created {len(tasks)} clips")

Each task runs asynchronously. Poll the task status or use a webhook to know when your clips are ready.

Tweak the output

The example above produces 1080x1920 vertical clips for Reels and TikTok. Adjust width, height, and format for other platforms:

PlatformWidthHeightNotes
Reels / TikTok108019209:16 vertical
YouTube Shorts10801920Same as Reels
X / Twitter128072016:9 landscape
Square (feed)108010801:1

You can also fire multiple Ittybit tasks per clip to produce several sizes at once.

See also