TikTok drives product trends faster than any other platform -- a product can go from unknown to sold out in days. Detecting trends early gives ecommerce brands and dropshippers a crucial advantage. This tutorial builds a trend detection pipeline using the Scavio TikTok API that monitors product-related hashtags, tracks view velocity, and identifies emerging products before they peak. The system analyzes hashtag growth rates, creator adoption patterns, and engagement ratios to generate trend scores. Each detection run costs 5-10 credits ($0.025-0.05).
Prerequisites
- Python 3.9+ installed
- requests library installed
- A Scavio API key from scavio.dev
- Product categories or niches to monitor
Walkthrough
Step 1: Define product monitoring categories
Set up the product categories and related search terms to monitor. Each category has multiple keywords to catch different angles of the same trend.
categories = {
'skincare': {
'keywords': ['skincare routine', 'skincare haul', 'skincare viral',
'skincare hack', 'skincare tiktok made me buy'],
'hashtags': ['skincareroutine', 'skincarehaul', 'tiktokmademebuyit']
},
'tech_gadgets': {
'keywords': ['tech gadget viral', 'amazon finds tech',
'tiktok gadget review', 'must have tech 2026'],
'hashtags': ['techfinds', 'amazontechfinds', 'gadgetreview']
},
'kitchen': {
'keywords': ['kitchen gadget tiktok', 'cooking hack viral',
'amazon kitchen finds', 'kitchen must have'],
'hashtags': ['kitchenhacks', 'kitchenfinds', 'cookingtiktok']
}
}
total_searches = sum(len(c['keywords']) + len(c['hashtags']) for c in categories.values())
print(f'{len(categories)} categories, {total_searches} total API calls')
print(f'Estimated cost per run: ${total_searches * 0.005:.2f}')Step 2: Search for trending product videos
For each keyword, search TikTok and collect video data. Track plays, likes, and creation times to calculate velocity metrics.
import requests, os, time
API_KEY = os.environ['SCAVIO_API_KEY']
TIKTOK_URL = 'https://api.scavio.dev/api/v1/tiktok'
def search_tiktok(keyword: str, count: int = 20) -> list:
resp = requests.post(f'{TIKTOK_URL}/search/videos',
headers={'Authorization': f'Bearer {API_KEY}',
'Content-Type': 'application/json'},
json={'keyword': keyword, 'count': count, 'cursor': 0})
resp.raise_for_status()
videos = resp.json().get('data', {}).get('videos', [])
return [{
'id': v.get('id', ''),
'author': v.get('author', {}).get('uniqueId', ''),
'desc': v.get('desc', ''),
'plays': v.get('stats', {}).get('playCount', 0),
'likes': v.get('stats', {}).get('diggCount', 0),
'comments': v.get('stats', {}).get('commentCount', 0),
'shares': v.get('stats', {}).get('shareCount', 0),
'create_time': v.get('createTime', 0),
'keyword': keyword
} for v in videos]Step 3: Extract product names from video descriptions
Parse video descriptions to identify specific product names and brands. Videos often mention the exact product name, brand, or Amazon ASIN.
import re
from collections import Counter
def extract_products(videos: list) -> Counter:
"""Extract product mentions from video descriptions."""
product_counter = Counter()
# Common patterns: "Product Name" in caps, @brand mentions, #productname
for v in videos:
desc = v.get('desc', '')
# Hashtag products (e.g., #CeraVe #StanleyCup)
hashtags = re.findall(r'#(\w+)', desc)
for tag in hashtags:
# Filter out generic tags
if len(tag) > 3 and tag.lower() not in {
'fyp', 'foryou', 'viral', 'trending', 'tiktok',
'skincare', 'review', 'haul', 'musthave'}:
product_counter[tag.lower()] += 1
# Brand mentions (capitalized words that look like brand names)
brands = re.findall(r'\b([A-Z][a-zA-Z]+(?:\s[A-Z][a-zA-Z]+)?)\b', desc)
for brand in brands:
if len(brand) > 3 and brand.lower() not in {'this', 'that', 'the', 'with'}:
product_counter[brand.lower()] += 1
return product_counter
# Example:
products = extract_products(search_tiktok('skincare viral'))
for product, count in products.most_common(10):
print(f' {product}: {count} mentions')Step 4: Calculate trend velocity scores
Score each product based on how quickly its mentions are growing. High view velocity plus many unique creators signals a trending product.
import statistics
from datetime import datetime
def calculate_trend_score(product: str, videos: list) -> dict:
relevant = [v for v in videos if product in v.get('desc', '').lower()]
if len(relevant) < 2:
return {'product': product, 'trend_score': 0, 'reason': 'Too few videos'}
total_plays = sum(v['plays'] for v in relevant)
total_engagement = sum(v['likes'] + v['comments'] + v['shares'] for v in relevant)
unique_creators = len(set(v['author'] for v in relevant))
# Recency: weight recent videos more heavily
now = time.time()
recency_scores = []
for v in relevant:
age_days = (now - v['create_time']) / 86400 if v['create_time'] > 0 else 30
recency_scores.append(max(0, 1 - (age_days / 30))) # 0-1, 1=today
avg_recency = statistics.mean(recency_scores)
# Composite trend score
play_score = min(total_plays / 100000, 40) # up to 40 points
creator_score = min(unique_creators * 5, 30) # up to 30 points
recency_score = avg_recency * 30 # up to 30 points
total_score = round(play_score + creator_score + recency_score, 1)
return {
'product': product,
'trend_score': total_score,
'total_plays': total_plays,
'unique_creators': unique_creators,
'video_count': len(relevant),
'avg_recency': round(avg_recency, 2)
}Step 5: Run the full trend detection pipeline
Combine all steps into a single pipeline that scans categories, extracts products, scores trends, and outputs a ranked report.
def detect_trends(categories: dict) -> list:
all_videos = []
credits_used = 0
for category, config in categories.items():
print(f'Scanning {category}...')
for keyword in config['keywords']:
videos = search_tiktok(keyword, count=20)
all_videos.extend(videos)
credits_used += 1
time.sleep(0.3)
# Extract and score products
product_counts = extract_products(all_videos)
trends = []
for product, count in product_counts.most_common(20):
if count >= 3: # minimum mention threshold
score = calculate_trend_score(product, all_videos)
if score['trend_score'] > 10:
trends.append(score)
trends.sort(key=lambda t: t['trend_score'], reverse=True)
print(f'\nDetected {len(trends)} trending products')
print(f'Credits used: {credits_used} (${credits_used * 0.005:.2f})')
for t in trends[:10]:
emoji_bar = '#' * int(t['trend_score'] / 5)
print(f' [{t["trend_score"]:5.1f}] {t["product"]}: '
f'{t["total_plays"]:,} plays, {t["unique_creators"]} creators '
f'{emoji_bar}')
return trends
trends = detect_trends(categories)Python Example
import os, requests, time, re
from collections import Counter
API_KEY = os.environ['SCAVIO_API_KEY']
TT = 'https://api.scavio.dev/api/v1/tiktok'
def search(keyword, count=20):
resp = requests.post(f'{TT}/search/videos',
headers={'Authorization': f'Bearer {API_KEY}', 'Content-Type': 'application/json'},
json={'keyword': keyword, 'count': count, 'cursor': 0})
return resp.json().get('data', {}).get('videos', [])
def detect_trends(keywords):
all_videos = []
for kw in keywords:
all_videos.extend(search(kw))
time.sleep(0.3)
products = Counter()
for v in all_videos:
for tag in re.findall(r'#(\w{4,})', v.get('desc', '')):
if tag.lower() not in {'fyp', 'foryou', 'viral', 'trending'}:
products[tag.lower()] += 1
print(f'Scanned {len(all_videos)} videos, found {len(products)} products')
for product, count in products.most_common(10):
print(f' {product}: {count} mentions')
return products
detect_trends(['skincare viral', 'amazon finds 2026', 'tiktok made me buy'])JavaScript Example
const API_KEY = process.env.SCAVIO_API_KEY;
const TT = 'https://api.scavio.dev/api/v1/tiktok';
async function searchTikTok(keyword) {
const resp = await fetch(`${TT}/search/videos`, {
method: 'POST',
headers: { 'Authorization': `Bearer ${API_KEY}`, 'Content-Type': 'application/json' },
body: JSON.stringify({ keyword, count: 20, cursor: 0 })
});
return (await resp.json()).data?.videos || [];
}
async function detectTrends(keywords) {
const products = {};
for (const kw of keywords) {
const videos = await searchTikTok(kw);
videos.forEach(v => {
const tags = (v.desc || '').match(/#(\w{4,})/g) || [];
tags.forEach(t => {
const tag = t.slice(1).toLowerCase();
if (!['fyp', 'foryou', 'viral'].includes(tag)) {
products[tag] = (products[tag] || 0) + 1;
}
});
});
}
Object.entries(products).sort((a, b) => b[1] - a[1]).slice(0, 10)
.forEach(([p, c]) => console.log(` ${p}: ${c} mentions`));
}
detectTrends(['skincare viral', 'amazon finds 2026']);Expected Output
Scanning skincare...
Scanning tech_gadgets...
Scanning kitchen...
Detected 8 trending products
Credits used: 12 ($0.06)
[ 78.5] cerave: 1,234,000 plays, 15 creators ################
[ 65.2] stanleycup: 890,000 plays, 12 creators #############
[ 52.1] dysonairwrap: 567,000 plays, 8 creators ###########
[ 45.8] theordinary: 445,000 plays, 9 creators #########
[ 38.4] airfryer: 334,000 plays, 7 creators ########
[ 31.0] laneige: 234,000 plays, 6 creators ######
[ 24.5] owala: 178,000 plays, 5 creators #####
[ 18.2] hexclad: 123,000 plays, 4 creators ####