AI search visibility tools track citations in ChatGPT, Perplexity, and Google AI Mode. This tutorial walks the DIY layer that pairs with any tracker — daily citation pulls into DuckDB for delta tracking.
Prerequisites
- Python 3.10+
- Scavio API key
- DuckDB
Walkthrough
Step 1: Define brand keyword set
10-30 brand and category keywords.
KEYWORDS = ['scavio', 'best mcp search server', 'tavily alternative', 'search api for ai agents']Step 2: AI Overviews citations via Scavio
include_ai_overview surfaces the citation list.
import requests, os
API_KEY = os.environ['SCAVIO_API_KEY']
def ai_overview(q):
r = requests.post('https://api.scavio.dev/api/v1/search',
headers={'x-api-key': API_KEY},
json={'query': q, 'include_ai_overview': True}).json()
return (r.get('ai_overview') or {}).get('citations', [])Step 3: Reddit thread tracking
Reddit citations precede AI Overview citations.
def reddit_mentions(q):
r = requests.post('https://api.scavio.dev/api/v1/reddit/search',
headers={'x-api-key': API_KEY}, json={'query': q}).json()
return r.get('posts', [])Step 4: Persist into DuckDB
One row per (keyword, surface, citation, date).
import duckdb, datetime
db = duckdb.connect('citations.duckdb')
db.execute('CREATE TABLE IF NOT EXISTS citations(keyword TEXT, surface TEXT, url TEXT, date DATE)')
for k in KEYWORDS:
today = datetime.date.today()
for c in ai_overview(k):
db.execute('INSERT INTO citations VALUES (?, ?, ?, ?)', (k, 'ai_overview', c, today))
for p in reddit_mentions(k):
db.execute('INSERT INTO citations VALUES (?, ?, ?, ?)', (k, 'reddit', p['url'], today))Step 5: Friday delta query
What's new vs last Friday?
delta = db.execute('''
SELECT keyword, surface, url
FROM citations
WHERE date >= current_date - INTERVAL 7 days
AND url NOT IN (SELECT url FROM citations WHERE date < current_date - INTERVAL 7 days)
''').fetchall()Python Example
# See steps above. Daily run: 30 keywords × 2 calls = 60 credits = $0.26 on Project tier.JavaScript Example
// Same pattern in TS with duckdb-async.Expected Output
Daily citation log per surface. Friday delta email with new and lost citations per keyword.