stophy
Official TypeScript SDK for Stophy YouTube context API for AI agents. Search videos, fetch transcripts, read comments and live chat, inspect channels and playlists, use YouTube Music and YouTube Kids, and get autocomplete suggestions, all returned as structured JSON.
Install
npm install stophy
Get an API key from your Stophy dashboard. The SDK sends it as Authorization: Bearer <key> on every request.
Quick start
import { Stophy } from "stophy";
const stophy = new Stophy();
const result = await stophy.transcript(
"https://www.youtube.com/watch?v=D7liwdjvhWc",
);
console.log(result.data.text);
Methods
stophy.videoDetails(url) | Video metadata and related videos |
stophy.transcript(url) | Timestamped captions and full text |
stophy.comments(url, options?) | Top-level comments |
stophy.replies(token) | Replies for a comment thread |
stophy.liveChat(url, options?) | Live stream chat messages |
stophy.search(query, options?) | Search with filters |
stophy.channel(url, options?) | Channel metadata and content |
stophy.playlist(url, options?) | Playlist items, paginated |
stophy.suggest(query, options?) | Search autocomplete suggestions |
stophy.music(body) | YouTube Music search, suggestions, songs, lyrics, albums, artists, playlists |
stophy.kids(body) | YouTube Kids search and video metadata |
stophy.credits() | Current credit balance |
stophy.logs(query?) | Recent request logs |
stophy.usage(query?) | Daily credit/request counts |
Examples
const results = await stophy.search("typescript tutorial", {
sortBy: "popularity",
duration: "long",
});
const comments = await stophy.comments(videoUrl, { sortBy: "top" });
const firstReplyToken = comments.data.items[0]?.repliesToken;
if (firstReplyToken) {
const replies = await stophy.replies(firstReplyToken);
}
const channel = await stophy.channel("https://www.youtube.com/@mkbhd", {
tab: "video",
});
const { data: s } = await stophy.suggest("react", { hl: "en", gl: "US" });
console.log(s.suggestions);
const music = await stophy.music({
type: "search",
q: "lofi",
searchType: "song",
});
console.log(music.data.items);
const kids = await stophy.kids({ type: "search", q: "science" });
console.log(kids.data.items);
console.log((await stophy.credits()).data.credits);
List endpoints return a continuationToken. Pass it back in to fetch the next page:
let token: string | undefined;
do {
const page = await stophy.search("lofi", { continuationToken: token });
token = page.data.continuationToken ?? undefined;
} while (token);
Errors
Non-2xx responses throw a StophyError:
import { Stophy, StophyError } from "stophy";
try {
await stophy.credits();
} catch (err) {
if (err instanceof StophyError) {
console.error(err.status, err.code, err.message, err.requestId);
}
}
License
MIT