TikTok API — Getting Started — FetchLayer Docs
Documentation menu
FetchLayer FetchLayer API

Getting Started

Read public TikTok accounts, videos, hashtags, search results and comments as structured JSON. No TikTok account and no TikTok developer application — just your FetchLayer key.

1. Get your API key

Create an account and generate a FetchLayer API key from your dashboard. The same key works on every platform.

Create free account →

2. Read an account

Pass a handle with or without the @, or a profile URL. The counts come back exact rather than rounded.

bash
curl -X POST https://api.fetchlayer.dev/tiktok/user-profile \
  -H "Authorization: Bearer ss-your-key" \
  -H "Content-Type: application/json" \
  -d '{"username":"@nasa"}'

Exact counts, not rounded ones

TikTok publishes both the rounded figure shown on the page and the precise one. This returns the precise pair, so a follower count comes back as 1719888 rather than 1.7M — which is the difference between being able to track week-to-week movement and not.

3. List what they posted

The account's profile comes back with the videos, so listing an account's posts does not also need a profile call. Sort by latest, popular or oldest.

bash
curl -X POST https://api.fetchlayer.dev/tiktok/user-videos \
  -H "Authorization: Bearer ss-your-key" \
  -H "Content-Type: application/json" \
  -d '{"username":"@nasa","limit":50,"sort":"popular"}'

Page with the cursor, not the offset

When more results exist, hasMore is true and nextCursor carries an opaque value. Pass it back as cursor to continue. pages collects several pages inside one request instead, up to 20 — each page read is one credit, and the response reports how many as pagesFetched.

This is the one route TikTok declines most often. The service retries internally before answering, so a 503 here means those retries have already failed — wait before trying again rather than retrying immediately.

4. Search, or follow a hashtag

Search returns TikTok's own ranking for the term. A hashtag listing also returns the tag itself, with its total view count across TikTok — useful for sizing a trend before deciding how much of it to read.

bash
curl -X POST https://api.fetchlayer.dev/tiktok/search-videos \
  -H "Authorization: Bearer ss-your-key" \
  -H "Content-Type: application/json" \
  -d '{"query":"space launch","limit":50}'

curl -X POST https://api.fetchlayer.dev/tiktok/hashtag-videos \
  -H "Authorization: Bearer ss-your-key" \
  -H "Content-Type: application/json" \
  -d '{"hashtag":"nasa","limit":50}'

Search takes no sort and no date filter

TikTok offers a public caller neither, so neither is accepted. Passing one is a 400 naming the field rather than a parameter that is quietly ignored — being answered with the wrong data and no indication why is worse than being told the request is wrong.

5. Read the comments

By video id or URL. Each comment carries its text, timestamp, like and reply counts, whether it is pinned, and whether the video's author wrote or liked it.

bash
curl -X POST https://api.fetchlayer.dev/tiktok/comments \
  -H "Authorization: Bearer ss-your-key" \
  -H "Content-Type: application/json" \
  -d '{"video":"https://www.tiktok.com/@nasa/video/7686148096895569165","limit":100}'

replies is not the whole thread

replies holds only the replies TikTok shows alongside a comment — usually none or a handful. replyCount reports how many exist in total, and a response where the two differ says so in notes. Separately, totalCount is the figure TikTok publishes for the video, and it can exceed what paging can reach.

6. Images, covers and clip links

TikTok's asset URLs are signed and expire within hours, so every asset carries a downloadUrl pointing at GET /tiktok/media, which re-fetches it on demand with Range support.

bash
curl -L "https://api.fetchlayer.dev/tiktok/media?url=<asset url>" \
  -H "Authorization: Bearer ss-your-key" \
  --output cover.jpg

Video files are not downloadable

TikTok answers an ordinary request for a clip's bytes with a 403 to every caller, including from the page that produced the URL — only its own player can read them. So /media serves images: photo-post frames, cover frames and avatars. A clip's url is still returned on the video, and that is what you use to open or embed it; asking /media for one returns a 404 saying the source refused it. No service reading the public site can hand over a video file.

Resolving a pasted link

When a user hands you a TikTok URL and you do not know what it points at, /resolve-url tells you — video, account, hashtag, sound or search — plus the id, handle, tag or query it encodes. It reaches TikTok not at all, so it is free.

bash
curl -X POST https://api.fetchlayer.dev/tiktok/resolve-url \
  -H "Authorization: Bearer ss-your-key" \
  -H "Content-Type: application/json" \
  -d '{"url":"https://www.tiktok.com/@nasa/video/7686148096895569165"}'

A shortened share link (vm.tiktok.com, vt.tiktok.com) carries no information about its target, so it comes back as unknown with a note saying to open it and pass the full URL. The routes that take a video reject a short link for the same reason.

Errors and retries

A 400 names the field to fix; unrecognised fields are rejected rather than ignored. A 404 means there is no such public account, video or hashtag. A 503 means the source declined and every internal retry had already failed, so retrying immediately is unlikely to help — wait first. Read notes on successful responses too: a private account, comments turned off, and a list that ran out early all announce themselves there rather than as an error.

Next steps