Track AI Mode Answer Sources with Python (2026)
Google AI Mode quietly graduated from "experimental tab" to "default behaviour on a lot of queries" in early 2026. For many of the keywords I care about — SaaS comparisons, developer questions, vendor research — AI Mode is now the first thing the user sees. The blue links are below the fold or hidden behind an "all" tab.
That raises a tracking question: does my domain appear in the source URLs returned with an AI Mode answer? This API measurement is separate from checking what Google's own AI Mode interface displayed.
This guide shows a Python script for comparing those API source URLs over time. AI Mode is an explicit paid Deep Search option; the sample output below is illustrative, not a verified Google citation report.
AI Mode vs AI Overviews — the distinction that matters
These are not the same surface and they don't behave the same way.
AI Overviews are short summaries that appear above the organic SERP for a subset of queries. Typically 100–200 words, 1–3 cited sources. Already familiar; you can read our deeper breakdown in the AIO optimization guide.
AI Mode is a separate conversational interface launched as a Search tab and rolled into defaults during 2025–2026. Longer responses, more cited sources, supports follow-up questions, and draws from a wider candidate pool than AIO. The official launch posts on Google's blog describe the user-facing differences in detail.
For brand visibility purposes the consequences are concrete:
- AI Mode cites more sources, so the "appearance probability" is higher per query but per-citation salience is lower.
- AI Mode draws from pages that don't always rank in the top 5 organically — structure and entity signals matter more than raw ranking.
- AI Mode is more recency-sensitive than AIO for a wider range of query categories.
Measure the two outputs separately. A source URL in either API field is a lead for review; confirm any claim about Google's displayed citations in its interface.
What the tracker tracks
Three columns per query, per week:
- AI Mode present? — was an AI Mode answer block returned at all
- Self cited? — is your domain in the AI Mode source list
- Position of citation — where in the source list you appear, if at all
At the run level, you can calculate the share of returned API answers whose source list includes your domain. Do not label that number Google's citation share without independent interface checks.
Prereqs
- Python 3.10+ and
requests - A Serpent API key with paid Deep Search access;
include_ai_mode=truecarries a separate charge - A CSV of tracked queries (one per line)
- 10 minutes
Step 1: Single-query fetcher
Save as aimode_fetch.py:
import os, requests
API_KEY = os.environ["SERPENT_API_KEY"]
URL = "https://apiserpent.com/api/search"
def fetch_aimode(query, country="us"):
"""Return presence and source URLs from this API's AI Mode answer."""
r = requests.get(URL, params={
"q": query, "num": 10, "country": country, "engine": "google",
"include_ai_mode": "true"
}, headers={"X-API-Key": API_KEY}, timeout=120)
r.raise_for_status()
aimode = r.json().get("aiMode") or {}
sources = aimode.get("sources", [])
return bool(aimode.get("answer") or sources), [s.get("url","") for s in sources]
The opt-in aiMode field is separate from results.aiOverview; one does not stand in for the other. The source URLs here describe this API response. They do not prove that Google showed those URLs in its AI Mode interface for the same query and country.
Step 2: Bulk runner
Save as aimode_run.py:
import csv, sys, datetime, time
from aimode_fetch import fetch_aimode
DOMAIN = "yourbrand.com" # change me
def run(queries_csv):
today = datetime.date.today().isoformat()
out = f"aimode-{today}.csv"
with open(queries_csv) as f, open(out, "w", newline="") as g:
w = csv.writer(g)
w.writerow(["date","query","present","self_cited","position","first_3_sources"])
for row in csv.reader(f):
q = row[0].strip()
if not q: continue
try:
present, sources = fetch_aimode(q)
pos = next((i+1 for i, s in enumerate(sources) if DOMAIN in s), None)
w.writerow([today, q, present, pos is not None, pos or "", " | ".join(sources[:3])])
print(today, q, "OK", "cited" if pos else "miss")
except Exception as e:
w.writerow([today, q, "ERR", "", "", str(e)])
print(today, q, "ERR", e)
time.sleep(0.2)
print("wrote", out)
if __name__ == "__main__":
run(sys.argv[1] if len(sys.argv) > 1 else "queries.csv")
Make a queries.csv with one query per line (your tracked keywords), then:
python aimode_run.py queries.csv
You get back aimode-2026-05-27.csv with the day's snapshot. Re-run weekly via cron.
Step 3: Weekly diff
The single-day snapshot is fine. The weekly diff is where insight lives. Save as aimode_diff.py:
import csv, sys, glob, datetime
def load(path):
out = {}
with open(path) as f:
for row in csv.DictReader(f):
out[row["query"]] = row
return out
def diff(old_path, new_path):
a, b = load(old_path), load(new_path)
changed = []
for q in sorted(set(a) | set(b)):
oa = a.get(q, {}).get("self_cited", "")
ob = b.get(q, {}).get("self_cited", "")
if oa != ob:
changed.append({"query": q, "was": oa, "now": ob,
"now_pos": b.get(q, {}).get("position", ""),
"now_sources": b.get(q, {}).get("first_3_sources","")})
for c in changed:
flag = "+ GAINED" if c["now"] == "True" else "- LOST "
print(f"{flag} {c['query']} pos={c['now_pos']}")
if c["now_sources"]:
print(f" top3: {c['now_sources']}")
if __name__ == "__main__":
files = sorted(glob.glob("aimode-*.csv"))
if len(files) < 2:
print("Need at least 2 snapshots to diff")
sys.exit(1)
diff(files[-2], files[-1])
Output looks like:
+ GAINED best vector database 2026 pos=4
top3: example.com/vector | pinecone.io/learn | yourbrand.com/blog/...
- LOST cheap serp api pos=
+ GAINED serpapi alternatives pos=2
top3: yourbrand.com/serpapi-alts | reddit.com/r/saas/... | g2.com/...
These rows flag changes in the API source list for review. Confirm the original interface before calling one a gained or lost Google citation.
How to read the report
Two derived metrics matter more than the raw rows.
1. API source share. Of the returned AI Mode answers, what percentage of source lists include your domain? Compare that percentage over time and keep it separate from verified Google citation share. For wider context, see AI search visibility metrics.
2. Stability ratio. Of queries where your domain appeared in last week's API source list, what percent include it this week? Treat changes as prompts to inspect the answer and source pages; the API row alone does not identify the cause.
Playbook for moving the needle
Once you have the data, three plays consistently outperform.
1. Refresh the pages you lost
If a page drops from the returned source list, review the answer, the page and competing pages before deciding whether a content refresh is warranted. See our freshness study for a separate refresh example.
2. Add schema to gainers
For a newly listed page, check whether its structured data accurately describes visible content. Do not infer that markup alone caused or will preserve an API source entry.
3. Identify "almost there" queries
For queries where your page appears lower in the returned source list, inspect relevance and answer context before changing it. The list order is an API observation, not a Google ranking.
For broader brand-side tracking that covers ChatGPT, Claude, Gemini, and Perplexity in one call, see our cross-LLM citation tracker — the AI Rank API powers it.
What I check before declaring a problem
Three quick checks before treating a citation drop as a real problem:
Did this API call return an empty AI Mode answer? Repeat the call and check its eligibility before inferring anything about Google's own interface.
Did the query intent change? Sometimes Google reinterprets a query (e.g. "apple" shifting from fruit-leaning to product-leaning seasonally). The citation pool changes with intent. Check organic results too.
Did a fresh competitor publish? site:competitor.com 2026 often shows whether a relevant new page launched in the last week. If yes, your refresh is the right response.
FAQ
How is AI Mode different from AI Overviews?
AI Mode is a longer, conversational answer surface with broader source selection; AI Overviews are short summaries above the organic SERP. Different tracking, sometimes different rankings.
Can a SERP API detect AI Mode answers?
On eligible paid Deep Search calls, include_ai_mode=true adds a top-level aiMode answer and source list. This API output does not establish which citations appeared in Google's AI Mode interface.
How often should I run the tracker?
Weekly for most brands. Daily during active campaigns, big content pushes, or after algorithm changes.
What if my domain disappears one week and reappears the next?
AI Mode citation variance is higher than organic ranking variance. Track the stability ratio over 4 weeks; week-to-week noise is normal.
Can I track AI Mode across multiple countries?
Yes. Pass country to the fetcher and compare API outputs by market. Check Google's interface separately before attributing a difference to its rollout.
Start Tracking AI Mode Citations Today
Serpent's Google SERP API can return an AI Mode answer and source URLs when requested with include_ai_mode=true on eligible paid Deep Search calls. Review Google's interface separately for display claims.
Explore: Google SERP API · AI Rank API · Pricing



