Before you start
- Get an API keySign up for 100 free credits, no card. Keys start with
gs_live_. - Put it in the environmentEvery example reads it from
GROUNDSOCIAL_API_KEY:export GROUNDSOCIAL_API_KEY=gs_live_… - Set up TypeScript
npm init -y && npm pkg set type=module && npm i -D tsx typescript @types/node
Call TikTok top videos API from TypeScript
GET /v1/tiktok/trending/videos. Save this as main.ts and run npx tsx main.ts. It reads the items in entityInfos and prints itemInfo.title and itemAuthorMetrics.followers for each.
// The fields this script reads, as the recorded response has them.
interface Page {
entityInfos: {
itemInfo: {
title: string
}
itemAuthorMetrics: {
followers: string
}
}[]
}
class ApiError extends Error {
constructor(
readonly code: string,
readonly hint: string,
readonly retryable: boolean,
) {
super(`${code}: ${hint}`)
}
}
async function call<T>(path: string, params: Record<string, string> = {}): Promise<T> {
const url = new URL(path, 'https://api.groundsocial.dev')
for (const [k, v] of Object.entries(params)) url.searchParams.set(k, v)
const res = await fetch(url, {
headers: {
Authorization: `Bearer ${process.env.GROUNDSOCIAL_API_KEY}`,
},
signal: AbortSignal.timeout(60_000),
})
if (!res.ok) {
const { error } = (await res.json()) as {
error: { code: string; message: string; hint?: string; retryable: boolean }
}
throw new ApiError(error.code, error.hint ?? error.message, error.retryable)
}
return (await res.json()) as T
}
const data = await call<Page>('/v1/tiktok/trending/videos', { country: 'US', period: '7' })
for (const item of data.entityInfos) {
console.log(item.itemInfo?.title, item.itemAuthorMetrics?.followers)
}The response
A real TikTok response to this call, recorded from the live source and shortened for display: arrays keep their first items and … marks every cut. The recorded page had 2 items in entityInfos. Live calls return current data in the same shape.
{
"entityInfos": [
{
"itemInfo": {
"itemID": "7691731357294152974",
"authorID": "7532541110103867406",
"contentType": 1,
"coverURL": "https://p16-common-sign.tiktokcdn-us.com/tos-useast5-p-0068-tx/oogoQFgR5EB6M0TqAyC2QhQefQE…",
"coverURLList": [
{
"…": "2 fields"
},
{
"…": "2 fields"
}
],
"createTime": "1790870796",
"creatorID": "6992810747127628805",
"title": "AD sparkling through the city, as part of #thediamondcollective @The Diamond Collective ",
"videoURL": "https://v16m-default.tiktokcdn-us.com/bc115036eff2290f90ca4abccb5c97e0/6b067eb5/video/tos/…"
},
"itemAuthorInfo": {
"avatarURI": "https://p16-common-sign.tiktokcdn-us.com/tos-useast5-avt-0068-tx/5a124cccf2dadf0c7e34d0f4a…",
"bio": "NYC\nArtist--multicurious lover\n⭐️subscribe to my youtube⭐️\nsebin@dulcedo.com",
"handlerName": "deathstatequilibrium",
"nickName": "sebin🌟"
},
"itemMetrics": {
"engagementRate": 0.0004565897757430412,
"engagementRateLifeTime": 0.0007131562268624228,
"organicVideoViews": "5017483",
"organicVideoViewsLifeTime": "31217086",
"sixSecondsVTR": 0.009636825498597203,
"sixSecondsVTRLifeTime": 0.011701371964817882,
"videoViews": "51878078",
"videoViewsLifeTime": "234968151"
},
"itemAuthorMetrics": {
"followers": "117256"
}
},
{
"itemInfo": {
"itemID": "7678479724896587038",
"authorID": "7070293872819044358",
"contentType": 1,
"coverURL": "https://p16-common-sign.tiktokcdn-us.com/tos-useast8-p-0068-tx2/ocK3E0iPwBkRoAA5XXAPvCEAiB…",
"coverURLList": [
{
"…": "2 fields"
},
{
"…": "2 fields"
}
],
"createTime": "1787785387",
"creatorID": "6880574638150697990",
"title": "Five years ago, I started my small business with no idea what it would grow into. From wor…",
"videoURL": "https://v16m-default.tiktokcdn-us.com/37a23ad1f71c39e1dfd697f1ad694d53/6b067ec4/video/tos/…"
},
"itemAuthorInfo": {
"avatarURI": "https://p16-common-sign.tiktokcdn-us.com/tos-useast8-avt-0068-tx2/7d6ee80f6e94a044a88786ee…",
"bio": "your favorite hand-drawn crewnecks & tees\n🧸🤍🎨\nentrepreneur & nurse\nShop Below ◡̈",
"handlerName": "megannco",
"nickName": "Meg Ann Co."
},
"itemMetrics": {
"engagementRate": 0.0013633322396169325,
"engagementRateLifeTime": 0.0016093465367882222,
"organicVideoViews": "5187904",
"organicVideoViewsLifeTime": "19207771",
"sixSecondsVTR": 0.030609222943414737,
"sixSecondsVTRLifeTime": 0.03216759125618045,
"videoViews": "42046244",
"videoViewsLifeTime": "195686257"
},
"itemAuthorMetrics": {
"followers": "271347"
}
}
],
"periodEndTimestamp": "1795392000",
"page": 1,
"hasMore": false
}Top-level fields
| Field | Type | Description |
|---|---|---|
entityInfos | object[] | – |
periodEndTimestamp | string | – |
page | number | – |
hasMore | boolean | – |
Parameters
| Name | In | Type | Description |
|---|---|---|---|
country | query | string | Market (default US). |
period | query | "7" | "30" | Days: 7 (default) or 30. One of 7, 30. |
order | query | "views" | "engagement" | "completion" | views (default), engagement or completion. One of views, engagement, completion. |
page | query | integer | Page, from 1. |
Errors and retries
Every error is JSON with error.code (stable: branch on it), message, hint (what to do next), docs_url and retryable. A failed call is never charged. Retry only when retryable is true, after the Retry-After header.
try {
const data = await call<Page>('/v1/tiktok/trending/videos', { country: 'US', period: '7' })
} catch (err) {
if (!(err instanceof ApiError)) throw err
if (err.code === 'insufficient_credits') console.error('Top up:', err.hint)
else if (err.code === 'target_not_found') console.error('Nothing there (not charged).')
else if (err.retryable) console.error('Try again after Retry-After:', err.hint)
else throw err
}| Status | Meaning |
|---|---|
200 | The video board. |
400 | Invalid input. Nothing was charged. |
401 | Missing or invalid API key. |
402 | Not enough credits, a spend cap was reached, or payment is required. |
403 | The target is private, or the account is suspended. |
404 | The account, video, comment, hashtag or sound does not exist on TikTok, or was removed. |
429 | Too many requests. Wait for Retry-After seconds. |
503 | TikTok is temporarily unavailable. Retryable; nothing was charged. |
Every error code and what to do about it.
Pricing
| Cost | |
|---|---|
| Per call | 1 credit per call |
| 1,000 calls | $1.00 on the starter pack, $0.40 at volume |
| No key (MPP or x402) | $0.01 per call |
| Failed call | Refunded, never charged |
Every response has x-credits-charged and x-credits-remaining headers. Credits never expire. Packs and calculator.
From an AI agent (MCP)
The same call is the tiktok_videos_popular tool on the hosted MCP server, so Claude, Cursor or any MCP client can make it without code. Add the server once:
claude mcp add --transport http groundsocial https://api.groundsocial.dev/mcpThen ask for it in words (“TikTok’s top-videos board for a market and period”), or call the tool directly:
{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "tiktok_videos_popular",
"arguments": {
"country": "US",
"period": "7"
}
}
}MCP setup for Claude Desktop, Cursor, VS Code and ChatGPT.
Study what wins
Read the top videos weekly and note their formats and sounds.
Questions
Which markets?
TikTok publishes this board for the US, Japan, Vietnam, Thailand and Indonesia.
Keep going
- This call in Python, JavaScript, Go, PHP, cURL.
- TikTok top videos API reference: every field and status code.
- TikTok tutorials and all TypeScript tutorials.
- TikTok API: every endpoint and price.
- How to scrape TikTok hashtag videos with TypeScript: Videos with a TikTok hashtag, about 30 a page.
- How to scrape TikTok sound videos with TypeScript: Videos using a TikTok sound, about 30 a page.
- How to scrape TikTok search suggestions with TypeScript: What TikTok’s search box suggests for a partial query.
- How to scrape TikTok search with TypeScript: TikTok videos for a keyword, 16 a page.
- How to scrape TikTok place videos with TypeScript: Videos tagged at a TikTok place, 30 a page.
- How to scrape TikTok effect videos with TypeScript: Videos made with a TikTok effect, 30 a page.
Run it on your own data
One key for TikTok and 76 more platforms, over REST or MCP. Free credits on signup, no card.
TikTok is a trademark of ByteDance Ltd. We are not affiliated with or endorsed by TikTok or ByteDance.