- Use cases
- RAG over social video
RAG over social video
Fetch timestamped transcripts, chunk them, and index them for retrieval.
The job
Segments carry start and end times, so an answer can link to the second it came from. Fetch, chunk by time, embed, and keep the video url as metadata.
Endpoints
Failed requests and cached repeats cost 0 credits. Send max_age_days to accept a recent cached copy. See credits and caching.
| Endpoint | Returns | Cost |
|---|---|---|
| YouTube search | 1 credit | |
| Transcript from any video URL | 1 credit | |
| YouTube video transcript | 1 credit | |
| Batch requests | The sum of each sub-request's charge | |
| Create a monitor | Free |
Recipe
- Search for the videos on your topic.
- Fetch a transcript with segments for each.
- Chunk by time, embed, store the url and start time.
1import os2import requests34API = "https://api.socialscrape.dev"5HEADERS = {"x-api-key": os.environ["SOCIALSCRAPE_API_KEY"]}678def get(path, **params):9 res = requests.get(API + path, headers=HEADERS, params=params, timeout=60)10 res.raise_for_status()11 return res.json()["data"]1213# YouTube search14found = get("/v1/youtube/search", query="retrieval augmented generation", type="video", duration="long")15# Transcript from any video URL16doc = get("/v1/transcript", url=found["items"][0]["url"])1718chunks, buf, start = [], [], None19for seg in doc["segments"]:20 start = seg["start"] if start is None else start21 buf.append(seg["text"])22 if seg["end"] - start >= 60:23 chunks.append({"url": doc["url"], "start": start, "text": " ".join(buf)})24 buf, start = [], None1const API = "https://api.socialscrape.dev";2const headers = { "x-api-key": process.env.SOCIALSCRAPE_API_KEY! };34async function get(path: string, params: Record<string, string | number | boolean>) {5 const query = new URLSearchParams(Object.entries(params).map(([k, v]) => [k, String(v)]));6 const res = await fetch(`${API}${path}?${query}`, { headers });7 if (!res.ok) throw new Error(`${res.status} ${await res.text()}`);8 return (await res.json()).data;9}1011// YouTube search12const found = await get("/v1/youtube/search", { query: "retrieval augmented generation", type: "video", duration: "long" });13// Transcript from any video URL14const doc = await get("/v1/transcript", { url: found.items[0].url });1516const chunks: { url: string; start: number; text: string }[] = [];17let buf: string[] = [];18let start: number | null = null;19for (const seg of doc.segments) {20 start ??= seg.start;21 buf.push(seg.text);22 if (seg.end - start >= 60) {23 chunks.push({ url: doc.url, start, text: buf.join(" ") });24 buf = [];25 start = null;26 }27}Calls use api.socialscrape.dev and return the shapes in the reference.
Good to know
Many transcripts at once go in one batch call. Agents can call the same endpoints as tools through the MCP server, which runs on your machine.
Related
Questions
Can an agent call this without glue code?
Yes, through the MCP server, which you run on your machine and which exposes the same endpoints as tools.