# Search TikTok from a Python script and get videos back as JSON

In Python, a TikTok search is one requests.post to https://api.routergrowth.com/v1/run: your key in the Authorization header, capability social.search, platform tiktok and a query. The response is JSON with the matching videos, their engagement and the run's charge, ready for pandas.

HTML page: https://www.routergrowth.com/tools/tiktok/api-python
Part of: [TikTok tools](https://www.routergrowth.com/tools/tiktok.md)

## The call

[`social.search`](https://www.routergrowth.com/catalog/social.search): Public posts matching a keyword on X, LinkedIn, Reddit, YouTube, TikTok, Instagram or Facebook: brand mentions, category conversations, competitor chatter.

Price on this network: $0.00525 per post plus $0.00175 per call, $0.002 minimum a call. The exact quote is shown before every run.

## What a real run returned

Run on 2026-10-19: 5 records in 5.3 s for $0.028. Personal fields are masked. Five TikTok videos for "sourdough starter", as the script would receive them: one passed two million views, one sits under 25k.

| created_at | text | views | likes |
|---|---|---|---|
| 2026-07-10 | ✨ Beginner Sourdough Starter (Measuring Cup Version) Day 1 ¼ cup bread flour ¼ cup filtered water Mix well, cover loosely, and let sit at r… | 2100000 | 178400 |
| 2026-05-02 | Don’t just throw it out. Usually you can bring starter back to life. It takes a couple days and a little effort but I think it’s SO worth i… | 24600 | 290 |
| 2026-10-01 | Fall is the PERFECT time to start your sourdough journey!!! @King Arthur Baking #sourdoughforbeginners #sourdoughstarter #sourdoughbeginner… | 358300 | 27500 |

## How to do it

1. **Set the key.** Export ROUTERGROWTH_API_KEY and pass it as Authorization: Bearer. There is no TikTok developer app to register.
2. **Post the search.** requests.post to /v1/run with capability social.search and input platform tiktok, query and limit, plus routing.max_cost.
3. **Load the posts.** response.json()['result']['posts'] is a list of dicts; flatten engagement into views, likes, replies and reposts columns.
4. **Poll long runs.** If status is not final yet, GET /v1/runs/<run_id> until done is true.

## Ask it like this

- Write a Python script that searches TikTok for each keyword in topics.txt and writes the top videos to a CSV. (`social.search`)
- Add a step: for every creator found, pull their last five videos and compute average views. (`social.search`, `social.posts`)

## Connect

MCP server: `https://api.routergrowth.com/mcp`

```bash
claude mcp add --transport http routergrowth https://api.routergrowth.com/mcp
```

```bash
npm install -g routergrowth && routergrowth setup
routergrowth run -c social.search -i '{"platform": "tiktok", "query": "sourdough starter", "limit": 5}'
```

```bash
curl -X POST https://api.routergrowth.com/v1/run \
  -H "Authorization: Bearer $ROUTERGROWTH_API_KEY" \
  -d '{"capability": "social.search", "input": {"platform": "tiktok", "query": "sourdough starter", "limit": 5}}'
```

## Worth knowing

- **Plain REST.** requests or httpx is enough. The CLI covers the same calls from a shell script.
- **Results are not date sorted.** This run returned videos from 2023 to 2026. Sort by created_at in your script when recency matters.
- **Not TikTok's API.** RouterGrowth is independent of TikTok and reads public videos. No TikTok SDK or token is involved.

## Questions

### Which Python library should I use?

Any HTTP client: requests, httpx or aiohttp. The API is JSON over HTTPS.

### What fields does each video have?

id, url, text, created_at, author, author_url, an engagement object (likes, replies, reposts, views) and is_video.

### How do I avoid paying twice on a retry?

Send an Idempotency-Key header; a repeated request with the same key returns the first run.

### Can I search hashtags from Python?

Yes. Put the hashtag in query; the call is the same.

## Related

- [Read a TikTok account's recent videos through one REST or MCP call](https://www.routergrowth.com/tools/tiktok/api.md)
- [Scrape the recent videos of a TikTok account, with their numbers](https://www.routergrowth.com/tools/tiktok/video-scraper.md)
- [Search TikTok for a keyword and get the videos back as rows](https://www.routergrowth.com/tools/tiktok/scraper.md)
- [Research a topic on TikTok without applying for the Research API](https://www.routergrowth.com/tools/tiktok/research-api.md)
- [Scrape a brand's TikTok profile into one record your agent can use](https://www.routergrowth.com/tools/tiktok/profile-scraper.md)
- [Scrape the comments under a TikTok video and read what viewers ask](https://www.routergrowth.com/tools/tiktok/comments-scraper.md)
- [How TikTok video data is billed: quoted before the run, charged per video](https://www.routergrowth.com/tools/tiktok/api-pricing.md)
