TikTok Scraper or API: Hashtag, Sound and Trend Data
A TikTok scraper is a program that loads public TikTok pages, follows hashtags and sounds, and pulls the posts and counts out of what each page sends back, with you fixing it every time something changes. The alternative is a set of TikTok endpoints that return the same public data as JSON at 1 credit per successful call. For trend work (which hashtags are rising in a country, how much a sound is used, what's posted on a topic), the endpoints cost about 2 credits per hashtag tracked a day. This post compares the two job by job.
Which TikTok data does a trend job need?
A trend job needs aggregate signals, not people. The questions are what's rising in a market, how often a hashtag or sound is used, and what gets posted about a topic. That narrows TikTok to four objects: the trending list for a country, a hashtag (the endpoints call these challenges), a sound, and keyword search over posts. Two more help with analysis: a single public video and its transcript.
Everything in this post stays inside that frame. The TikTok API in the catalogue also has user-level endpoints; this post leaves them out, because follower lists and individual tracking are a different job with a different legal footing. If your question is "who posted this" rather than "what is being posted", stop and read the terms before you build anything.
| Object | Question it answers | Endpoint | Required |
|---|---|---|---|
| Trending list | What's trending in this country? | GET /v1/tiktok/trending-hashtags |
country_code |
| Hashtag search | Which hashtags exist for this topic? | GET /v1/tiktok/challenges-search |
keywords |
| Hashtag | How big is this hashtag, and what's posted under it? | challenges-details, challenges-posts |
challenge_id or challenge_name |
| Sound | What's posted with this sound? | music-details, music-posts |
url, music_id |
| Keyword feed | What's posted about this topic? | GET /v1/tiktok/feed-search |
keywords |
| One video | What does this public video say? | GET /v1/tiktok/video, GET /v1/tiktok/transcript |
url (transcript: url or video_id) |
What does each piece cost to build yourself?
Every object in the table is a separate collector if you scrape it: its own pages to fetch, its own data to locate, its own paging to follow and its own way of breaking. The work below is general engineering for any large, script-heavy video platform, not a description of TikTok's systems. The endpoint side is what the catalogue lists.
Trending hashtags by country
A scraper has to fetch the trending view for each country you care about, which usually means sending requests that look like they come from that country, and then find the list inside the page or the data it loads. It has to do this on a fixed schedule, because a trend list only tells you something when you can compare it with earlier days.
The endpoint is one call per country and window: country_code (up to 2 characters) and time_range of 7 or 30. Ten countries checked daily is 10 × 30 = 300 credits a month.
Hashtags and the posts under them
A scraper resolves a hashtag to its page, reads whatever counts the page shows, then pages through its posts. Paging on a feed that loads as you scroll is the fragile part: the scraper has to reproduce whatever token or offset the page uses, and that tends to change without notice.
The endpoints split the job. challenges-search finds hashtags from keywords, challenges-details describes one by challenge_id or challenge_name, and challenges-posts returns its posts with count and cursor for paging and an optional region. Here is the catalogue's example search:
curl "https://api.perceptlayer.com/v1/tiktok/challenges-search?keywords=cosplay&count=10&cursor=0" \
-H "X-API-Key: $API_KEY"
Sounds and the posts that use them
Sounds work like hashtags for a scraper: a page per sound, counts to read and a feed of posts to page through. The extra step is resolving a sound from a video, since a sound is usually something you notice in a video first.
On the endpoints, music-details takes a sound's url, and music-posts takes a music_id with count and cursor. We have no recorded response for either, so check in the playground which value in the details response you pass as music_id.
Keyword search, single videos and transcripts
Search is the hardest page to scrape reliably, because results depend on filters and sorting the scraper has to drive through the interface. Transcripts are harder still: a scraper would have to find a caption track, or download audio and run speech recognition itself.
feed-search takes keywords plus optional region, publish_time, sort_type, count and cursor. The integer values publish_time and sort_type accept aren't documented here, so test them in the playground before you rely on them. video takes a public video's url and an optional hd flag; transcript takes a url or video_id and an optional language.
Which TikTok endpoints are restricted, and what do the terms allow?
The TikTok API includes restricted endpoints, because social data can identify people. A restricted endpoint works once you accept the restricted-endpoint terms in your dashboard; before that, a call returns restricted_endpoint (403) and costs nothing. The terms don't permit collecting personal data without a lawful basis, or using the data to contact people.
In practice that means three habits for a trend job. Aggregate before you store: keep counts per hashtag, sound and country, not rows per person. Don't build lists of accounts from post data, and never use anything you collect for outreach. And keep the raw responses only as long as your analysis needs them. Data is collected from publicly available sources and returned as found at the time of the call. The same rules apply to a scraper you write yourself, and you'd also have to read TikTok's terms before running one.
How do a TikTok scraper and the endpoints compare?
A scraper costs engineering time for each object it collects and carries blocking and terms risk; the endpoints cost credits per call and remove fetching, parsing and paging code. The table compares them for a recurring trend job, such as a daily report on hashtags and sounds in five countries.
| DIY TikTok scraper | TikTok endpoints | |
|---|---|---|
| Setup | One collector per object: trending, hashtag, sound, search, video | One API key in the X-API-Key header |
| Country targeting | Requests that appear to come from each country | country_code on trending-hashtags, region on posts and search |
| Paging | Reproduce the page's own scroll tokens | count and cursor |
| Transcripts | Find captions or run your own speech recognition | GET /v1/tiktok/transcript with an optional language |
| When pages change | Your parser breaks, often silently | You read JSON; there's no parser of yours to fix |
| Blocks and challenges | Yours to handle at volume | A failed call returns an error code and costs 0 |
| Speed | As fast as you can fetch without being blocked | 1 request a second free, at least 5 a second paid |
| Cost | Hosting, proxies if you use them, your time | 1 credit per successful call |
| Terms | TikTok's terms, plus privacy law | The restricted-endpoint terms, plus privacy law |
What does a tracked hashtag cost per day?
Cost follows calls, so price the job per item tracked. One hashtag checked daily with challenges-details and one page of challenges-posts is 2 calls × 1 credit = 2 credits a day. Fifty hashtags is 50 × 2 × 30 = 3,000 credits a month.
Add the trending list for 5 countries daily (5 × 30 = 150 credits) and one page of music-posts for 20 sounds daily (20 × 30 = 600 credits). The whole report is 3,000 + 150 + 600 = 3,750 credits a month: above the 100 free credits on signup, and inside the Starter pack's 10,000. Each extra page of posts is another call, so decide up front how deep you page per hashtag. See pricing for what credits cost and the credits docs for how calls are debited.
How would you collect a daily hashtag snapshot?
Without a recorded response, the safe pattern is to store each response as it arrives and work out the fields later in the playground. The script below calls challenges-details for a list of hashtags, saves each raw body to a dated file, and logs the credits each call used. It reads only the headers and the error format the docs define.
import datetime
import json
import os
import pathlib
import time
import requests
BASE = "https://api.perceptlayer.com"
HEADERS = {"X-API-Key": os.environ["API_KEY"]}
HASHTAGS = ["cosplay", "booktok", "streetfood"]
day = datetime.date.today().isoformat()
out = pathlib.Path("snapshots") / day
out.mkdir(parents=True, exist_ok=True)
for name in HASHTAGS:
while True:
r = requests.get(
f"{BASE}/v1/tiktok/challenges-details",
params={"challenge_name": name},
headers=HEADERS,
timeout=30,
)
if r.status_code == 429:
time.sleep(int(r.headers.get("Retry-After", "1")))
continue
break
if r.ok:
(out / f"{name}.json").write_text(json.dumps(r.json()))
print(name, "saved, credits used:", r.headers.get("X-Credits-Used"))
else:
print(name, "failed:", r.status_code, r.json()["error"]["code"])
time.sleep(1) # free accounts get 1 request a second
If every call fails with restricted_endpoint, accept the terms in the dashboard first. Whether challenge_name wants the name with or without a leading # isn't documented here; try both in the playground. Once you've seen the response, add a step that reads the counts you need into a table, and drop anything that identifies a person. The errors docs list every code, and the rate limits docs cover the per-account limit.
Which route should you choose?
Choose by what you're measuring and how often. The endpoints fit recurring, aggregate trend work; a scraper fits almost nothing here that the endpoints don't already cover. If you're a researcher, or building an app that creators sign in to, read TikTok API: Official Options and Public Trend Data for the official routes first.
| Use case | Route | Why |
|---|---|---|
| Daily trending hashtags in a few countries | trending-hashtags |
One call per country; 10 countries daily is 300 credits a month |
| Tracking a fixed list of hashtags | challenges-details and challenges-posts |
2 credits per hashtag per day at one page of posts |
| Measuring a sound's spread | music-details and music-posts |
Same pattern as hashtags, keyed by music_id |
| Topic research across posts | feed-search |
keywords with region, publish_time and sort_type |
| Analysing what videos say | video and transcript |
No speech recognition of your own |
| Academic research, or an app creators sign in to | An official route | See the official-options post linked above |
| Monitoring specific people or collecting followers | Neither | That's personal data; the terms don't permit it without a lawful basis, or for outreach |
| A one-off look at a few videos | A browser | Neither route is worth setting up |
For an agent that answers trend questions, add the MCP server as the AI agents docs describe; it finds the TikTok endpoints with search_endpoints and spends credits only on successful calls. Other social sources are under Social media. To see the fields for your market, accept the terms, run trending-hashtags in the playground on the TikTok API page, then get a free API key for the scheduled job.
APIs in this post
Frequently asked questions
Is scraping TikTok legal?
It depends on the data, the purpose and where you operate. Public, aggregate signals such as hashtag and sound counts carry the least risk; data about identifiable people brings privacy law into play. Read TikTok's terms before running a scraper, don't get around any protections, and get legal advice for a commercial data product.
Do I need to accept terms to use the TikTok endpoints?
Yes, because all of them are restricted. Accept the restricted-endpoint terms in your dashboard; until then the calls return restricted_endpoint (403) and cost nothing. The terms don't permit collecting personal data without a lawful basis or using it to contact people, so keep TikTok work to public videos, hashtags, sounds and trends in aggregate.
Can I get trending TikTok hashtags for one country?
Yes. GET /v1/tiktok/trending-hashtags takes a two-character country_code and an optional time_range of 7 or 30, for 1 credit per successful call. Follow a hashtag from the list with challenges-details and challenges-posts. GET /v1/tiktok/regions lists region codes.
What does a TikTok call return when it fails?
An HTTP status and a JSON body with error.code, error.message and error.request_id, plus X-Credits-Used: 0. Common codes are restricted_endpoint (403), invalid_parameters (422) for a missing country_code or keywords, and rate_limited (429), which carries a Retry-After header with the seconds to wait.
Can I get a TikTok video's transcript without a scraper?
Yes. GET /v1/tiktok/transcript takes a video's url or video_id and an optional language of up to 20 characters, for 1 credit per successful call. There's no recorded response in this post, so run it in the playground on the TikTok API page to see what comes back.