Build a Cross-Engine AI Share of Voice Tracker in Python
Your CEO asks a simple question: "When someone asks ChatGPT for the best tool in our category, how often do we come up?" If you can't answer that with a number, you're flying blind in the channel that's quietly replacing the blue links.
The metric that answers it is AI Share of Voice — the percentage of AI answers about your market that mention your brand. It's the same share-of-voice idea marketers have tracked for decades, ported to ChatGPT, Gemini, Perplexity, and Claude. And with over 400 million people using ChatGPT every week, it's no longer a vanity metric: firms that take answer-engine optimization seriously report meaningful revenue lift within a couple of quarters.
In this guide we'll build a tracker from scratch in Python — under 120 lines — that scores your share of voice across all four engines and shows you exactly where you're winning and losing.
The formula (and why it works)
Share of voice is refreshingly simple:
AI Share of Voice =
(answers mentioning you ÷ total answers) × 100
If you run 100 prompts across the engines and your brand shows up in 22 of the answers, your share of voice is 22%. Run the same prompts for a competitor and you can compare directly. The power isn't in any single number — it's in tracking the trend and benchmarking against rivals.
We covered the conceptual side in AI search visibility metrics; this post is the hands-on build.
Step 1: Build a prompt set
The prompt set is the methodology. Garbage prompts, garbage score. Mirror how real buyers ask, across three intents:
- Commercial — "best CRM for startups", "top project management tools 2026"
- Informational — "how do I track SEO rankings", "what is answer engine optimization"
- Brand — "is [your brand] any good", "[your brand] vs [competitor]"
Aim for 50–200 prompts. Keep them in a plain list so they're easy to version:
PROMPTS = [
"best serp api for developers",
"cheapest google search api 2026",
"how to track keyword rankings with an api",
"serp api alternatives to scraping google",
"best api to get google results as json",
# ...add 50-200 that match how your buyers ask
]
Step 2: Query the engines
We'll use the AI Rank API. Hand it a query plus your domain, and it queries all four engines, then tells you whether each one cited you. The key fields per request:
results.<engine>.target_found—trueif that engine cited your domainresults.<engine>.citations— every domain the engine cited (great for spotting competitors)aggregate.visibility_score— a 0–100 roll-up across engines for that one query
import os, requests
KEY = os.environ["SERPENT_API_KEY"]
def rank(query, domain):
r = requests.get("https://apiserpent.com/api/ai/rank",
params={"q": query, "domain": domain},
headers={"X-API-Key": KEY}, timeout=120)
r.raise_for_status()
return r.json()
Heads up: AI Ranking runs on paid credits (no free tier). A single all-engine call covers all four models in one request. See AI Rank pricing →
Step 3: Score share of voice
For each prompt, count whether you were mentioned (per engine and overall), and tally competitor domains while we're at it:
from collections import Counter
ENGINES = ["claude", "chatgpt", "gemini", "perplexity"]
def score(prompts, domain):
hits = {e: 0 for e in ENGINES}
overall = 0
competitors = Counter()
for q in prompts:
data = rank(q, domain)
res = data.get("results", {})
mentioned_anywhere = False
for e in ENGINES:
eng = res.get(e) or {}
if eng.get("target_found"):
hits[e] += 1
mentioned_anywhere = True
for c in eng.get("citations", []):
d = c.get("domain", "")
if d and domain not in d:
competitors[d] += 1
overall += 1 if mentioned_anywhere else 0
n = len(prompts)
return {
"overall_sov": round(100 * overall / n, 1),
"per_engine_sov": {e: round(100 * hits[e] / n, 1) for e in ENGINES},
"top_competitors": competitors.most_common(10),
}
The full script
Glue it together with a tiny report. That's the whole tool:
import os, requests
from collections import Counter
KEY = os.environ["SERPENT_API_KEY"]
DOMAIN = "yourdomain.com"
ENGINES = ["claude", "chatgpt", "gemini", "perplexity"]
PROMPTS = [
"best serp api for developers",
"cheapest google search api 2026",
"how to track keyword rankings with an api",
# ...your 50-200 prompts
]
def rank(query, domain):
r = requests.get("https://apiserpent.com/api/ai/rank",
params={"q": query, "domain": domain},
headers={"X-API-Key": KEY}, timeout=120)
r.raise_for_status()
return r.json()
def run():
hits = {e: 0 for e in ENGINES}
overall = 0
competitors = Counter()
for q in PROMPTS:
res = rank(q, DOMAIN).get("results", {})
seen = False
for e in ENGINES:
eng = res.get(e) or {}
if eng.get("target_found"):
hits[e] += 1; seen = True
for c in eng.get("citations", []):
d = c.get("domain", "")
if d and DOMAIN not in d:
competitors[d] += 1
overall += 1 if seen else 0
print(f" scored: {q[:42]:42} {'✅' if seen else '— '}")
n = len(PROMPTS)
print(f"\n=== AI Share of Voice for {DOMAIN} ===")
print(f"Overall: {round(100*overall/n,1)}% (across {n} prompts)")
for e in ENGINES:
print(f" {e:11}: {round(100*hits[e]/n,1)}%")
print("\nTop competitors cited instead of / alongside you:")
for d, c in competitors.most_common(8):
print(f" {c:3}x {d}")
if __name__ == "__main__":
run()
Reading the output
A typical first run looks something like this:
=== AI Share of Voice for yourdomain.com ===
Overall: 24.0% (across 50 prompts)
claude : 28.0%
chatgpt : 18.0%
gemini : 30.0%
perplexity : 20.0%
Top competitors cited instead of / alongside you:
31x competitor-a.com
22x competitor-b.com
14x bigreview-site.com
Three things to do with this:
1. Find your weakest engine. Here, ChatGPT is the gap. Dig into the prompts where ChatGPT cited competitors but the others cited you — that's your most fixable surface. (Our Claude vs AIO citation gap study shows how differently engines pick sources.)
2. Study who's winning. The competitor list tells you which pages the engines trust. Read them. The patterns — review round-ups, comparison tables, well-structured docs — are your content roadmap.
3. Save the numbers and re-run weekly. Append each run to a CSV. The trend line is the deliverable your CEO actually wanted.
From here you can layer on a chart, schedule it with cron, or wire alerts when your share dips. If you already run a rank tracker, this drops into the same scaffolding — see the 100-line rank tracker.
FAQ
What is AI Share of Voice?
The percentage of AI answers about your market that mention your brand: (answers mentioning you ÷ total answers) × 100. It's share of voice, applied to AI engines instead of media.
How many prompts do I need?
50–200 prompts that mirror real buyer questions across commercial, informational, and brand intent. Fewer is noisy; far more rarely changes the picture.
Which engines should I track?
The ones your buyers use. The AI Rank API covers Claude, ChatGPT, Gemini, and Perplexity in one call, with per-engine citations and a combined visibility score.
How often should it run?
Weekly for most brands; daily only during launches or reputation events. AI answers shift as models refresh, so regular snapshots beat one-off checks.
Measure Your AI Share of Voice
The AI Rank API checks Claude, ChatGPT, Gemini, and Perplexity in a single call and tells you exactly who they cite. Build your tracker today.
Get Your Free API KeyExplore: AI Rank API · Google SERP API · Playground · Docs


