Tutorial

How to Search TikTok Videos by Keyword via API

Search TikTok videos by keyword programmatically. Python and JavaScript examples using Scavio API with cursor-based pagination.

Search TikTok videos by keyword via Scavio API at $0.005/request. The search/videos endpoint returns video metadata with engagement stats, creator info, and pagination support for deep result sets.

Prerequisites

  • Scavio API key
  • Python 3.8+ or Node.js 18+
  • Target keyword or phrase

Walkthrough

Step 1: Run a video search

Search TikTok videos by keyword using the search/videos endpoint.

Python
import requests, os

HEADERS = {'Authorization': f'Bearer {os.environ["SCAVIO_API_KEY"]}',
           'Content-Type': 'application/json'}

resp = requests.post('https://api.scavio.dev/api/v1/tiktok/search/videos',
    headers=HEADERS,
    json={'keyword': 'productivity tools', 'count': 20, 'cursor': 0})

data = resp.json()['data']
for v in data.get('videos', []):
    print(f"{v['desc'][:50]} | {v['stats']['playCount']:,} plays")

Step 2: Paginate through results

Use cursor from the response for next page.

Python
if data.get('has_more'):
    page2 = requests.post(
        'https://api.scavio.dev/api/v1/tiktok/search/videos',
        headers=HEADERS,
        json={'keyword': 'productivity tools', 'count': 20,
              'cursor': data['cursor']}).json()['data']
    print(f'Page 2: {len(page2.get("videos", []))} results')

Python Example

Python
import requests, os

HEADERS = {'Authorization': f'Bearer {os.environ["SCAVIO_API_KEY"]}',
           'Content-Type': 'application/json'}

def search_videos(keyword, max_pages=3):
    videos = []
    cursor = 0
    for _ in range(max_pages):
        resp = requests.post('https://api.scavio.dev/api/v1/tiktok/search/videos',
            headers=HEADERS,
            json={'keyword': keyword, 'count': 20, 'cursor': cursor}).json()['data']
        videos.extend(resp.get('videos', []))
        if not resp.get('has_more'):
            break
        cursor = resp['cursor']
    return videos

results = search_videos('saas tools')
for v in results[:5]:
    print(f"{v['desc'][:40]} - {v['stats']['playCount']:,} plays")

JavaScript Example

JavaScript
const H = {'Authorization': `Bearer ${process.env.SCAVIO_API_KEY}`, 'Content-Type': 'application/json'};
async function searchVideos(keyword, maxPages = 3) {
  const videos = [];
  let cursor = 0;
  for (let i = 0; i < maxPages; i++) {
    const r = await fetch('https://api.scavio.dev/api/v1/tiktok/search/videos', {
      method: 'POST', headers: H,
      body: JSON.stringify({keyword, count: 20, cursor})
    }).then(r => r.json());
    videos.push(...(r.data.videos || []));
    if (!r.data.has_more) break;
    cursor = r.data.cursor;
  }
  return videos;
}
searchVideos('saas tools').then(v => console.log(`${v.length} videos found`));

Expected Output

JSON
Array of TikTok videos matching the keyword with engagement metrics, creator info, and video metadata. Paginated with cursor.

Related Tutorials

Frequently Asked Questions

Most developers complete this tutorial in 15 to 30 minutes. You will need a Scavio API key (free tier works) and a working Python or JavaScript environment.

Scavio API key. Python 3.8+ or Node.js 18+. Target keyword or phrase. A Scavio API key gives you 250 free credits per month.

Yes. The free tier includes 250 credits per month, which is more than enough to complete this tutorial and prototype a working solution.

Scavio has a native LangChain package (langchain-scavio), an MCP server, and a plain REST API that works with any HTTP client. This tutorial uses the raw REST API, but you can adapt to your framework of choice.

Start Building

Search TikTok videos by keyword programmatically. Python and JavaScript examples using Scavio API with cursor-based pagination.