What does it take to build your own AI visibility tracker?
An AI visibility tracker has five parts: a prompt set, collectors that ask each engine and keep the raw response, parsers that pull out answer text and citations, matchers that find brand mentions and owned domains, and a store that compares runs only when their conditions match. The collectors are the hardest part, because every engine returns citations in a different shape and the consumer apps have no official API.
This guide walks through each part as logic, with short pseudo-code. The settings and response fields come from the provider documentation and from the open-source code of CiteLadder, which runs this pipeline in production.[1] Provider APIs change often; check each linked page before you ship.
If you only want to check your own brand by hand, the guide to checking AI visibility is shorter. If you want definitions of citations and how to read them, see AI citation tracking.
Two ways to collect an answer
There are two kinds of source, and they measure different things:
| Route | What you call | What you get | Main limit |
|---|---|---|---|
| Model API with web search | OpenAI Responses, Anthropic Messages, Gemini, with a search tool | Answer text, inline citations, often the list of sources retrieved | An API answer is not what a signed-in user sees in the app |
| Search and app surfaces | A SERP or scraper provider such as DataForSEO | Google AI Overviews, AI Mode, ChatGPT and Gemini app answers | Slower, paid per task, and the response shape can change |
Store which route produced each answer, and never pool the two into one number without saying so.
Model APIs: turning on web search and reading citations
Without web search, a model answers from training data and cites nothing. Turn search on, cap the number of searches so cost stays predictable, and pass the market's country.
OpenAI (Responses API)
Add the web_search tool. Location goes on the tool as an approximate user_location with an ISO country code. Ask for web_search_call.action.sources in include to get every URL the model consulted, which is usually longer than the list it cites.[2]
request = {
model,
input: prompt,
max_output_tokens: 4096,
store: false,
tools: [{ type: 'web_search', user_location: { type: 'approximate', country: 'US' } }],
max_tool_calls: 2,
include: ['web_search_call.action.sources'],
};Reading the response:
- Answer text: every
output_textblock insidemessageitems inoutput. - Citations: annotations of type
url_citationon those blocks, each withurl,title,start_indexandend_index. The indexes point into the block's text, so you can store the exact cited span. - Searches:
web_search_callitems. Theiraction.sourcesare the sources retrieved. - Finish:
status, andincomplete_details.reasonwhen the output budget ran out. Arefusalblock means the model declined.
CiteLadder caps OpenAI at two tool calls per answer and every engine at 4,096 output tokens, both in configuration.[1]
Anthropic (Messages API)
Add the server tool web_search_20250305 named web_search, with max_uses to cap searches and an optional user_location. Search is billed at $10 per 1,000 searches on top of tokens.[3]
request = {
model,
max_tokens: 4096,
messages: [{ role: 'user', content: prompt }],
tools: [
{
type: 'web_search_20250305',
name: 'web_search',
max_uses: 2,
user_location: { type: 'approximate', country: 'US' },
},
],
};Reading the response:
contentinterleavesserver_tool_useblocks (the searches),web_search_tool_resultblocks (the results read) andtextblocks.- Citations sit on
textblocks as typeweb_search_result_location, withurl,titleand up to 150 characters ofcited_text. There are no character offsets. - The answer is the
textafter the last search block. Text before it is the model talking about its search. Join those blocks exactly as written, because one sentence can be split across several cited blocks. usage.server_tool_use.web_search_requestsgives the number of searches for cost.stop_reasonofpause_turnmeans the turn paused before the answer was finished. Anthropic lets you send the returned content back to continue it, which keeps the searches already paid for. CiteLadder keeps each attempt to one request, so it fails the attempt and retries.- A
web_search_tool_result_errorwithtoo_many_requestsis a rate limit, not an empty answer.
If extended thinking is on, it shares the output budget, so set it deliberately for answer capture. CiteLadder sets Claude's thinking mode in its route configuration for this reason.[1]
Google Gemini
Add the google_search tool. Google's current documentation shows grounded answers through the Interactions API, with url_citation annotations carrying url, title, start_index and end_index, and google_search_call steps carrying the queries. Grounding is billed at $14 per 1,000 search requests on Gemini 3 and newer, after 5,000 free requests a month.[4]
Two practical points:
- Citation titles in Google's examples are bare domains. CiteLadder reads the domain of a Gemini citation from its title.
- The response does not list the sources retrieved, so record them as unavailable for Gemini. It is not zero.
CiteLadder's Gemini API route has no location setting, so it measures only the project's default market there and marks other markets as not applicable.[1]
Perplexity and others
Perplexity's migration page says support for Sonar Chat Completions ended on 27 September 2026 and points developers to its Agent API, which returns a search_results output item.[5] If you add Perplexity, build against the Agent API and expect the shape to change. CiteLadder does not ship a Perplexity collector.
Whatever the provider, normalise every response into one record before analysis:
answer = {
engine, route, model, market, prompt_id, repetition,
text, finish_reason,
citations: [{ ordinal, url, title, domain, start, end, cited_text }],
sources_retrieved: [...] | null, // null = this engine does not expose it
search_queries: [...] | null,
usage: { input_tokens, output_tokens, searches },
raw_response,
}DataForSEO: Google AI Overviews, AI Mode and the ChatGPT and Gemini apps
DataForSEO is the practical way to read surfaces that have no official API. CiteLadder uses four of its endpoints.[1]
| Surface | Endpoint family | Settings CiteLadder sends |
|---|---|---|
| Google AI Overviews | /v3/serp/google/organic/task_post | location_code, language_code, device, os, depth: 10, load_async_ai_overview: true |
| Google AI Mode | /v3/serp/google/ai_mode/task_post | location_code, language_code, device, os |
| ChatGPT app | /v3/ai_optimization/chat_gpt/llm_scraper/task_post | location_code, language_code, priority: 1, force_web_search: true |
| Gemini app | /v3/ai_optimization/gemini/llm_scraper/task_post | location_code, language_code, priority: 1 |
Settings that matter
load_async_ai_overview: true. Without it, the organic SERP returns an AI Overview only from cache, so you undercount. With it, DataForSEO waits for the asynchronously loaded overview. It adds the base price again, refunded when no overview appears.[6][7]force_web_search: truefor ChatGPT. It makes the model search and cite current web pages, though DataForSEO does not guarantee citations.[8]- Location and language. Validate them against each surface's locations and languages lists before you submit. The lists differ by surface.
- Keyword encoding and length. The scraper accepts up to 2,000 characters, and
%and+must be sent as%25and%2B.[8] tag. Put your own task reference in it. It comes back on the result and in the task list, which is how you find a task whose submission response you lost.
Standard queue, polling and timing
Use the Standard queue: post a task, then fetch it by ID from task_get/advanced. It is the cheapest mode, and results stay retrievable for 30 days at no charge.[8] CiteLadder waits 15 seconds before the first poll and 60 seconds between polls, treats status codes 40601 and 40602 as still pending, and gives up after 75 polls.[1]
Status codes arrive in the response body. HTTP 200 does not mean success:
20000is success; a task post also accepts20100.40202and40209are rate limits. Nothing was created, so you can send again later.40200,40201and40204mean the account is unfunded, paused or unsubscribed. Stop submitting until it is fixed.
The rule that saves money: record your intent before you post a paid task, and never resubmit a task whose post timed out. It may have been accepted and charged. Search the task list (/v3/serp/id_list for SERP, /v3/ai_optimization/id_list for the scrapers) for your tag, with a time window and include_metadata: true, because the tag is only returned in the metadata. Poll only once you have a task ID.
saveIntent(task_ref)
try { id = post(payload with tag: task_ref) }
catch (timeout) {
id = findByTag(task_ref, window, include_metadata: true)
if (!id) return markUncertain(task_ref) // reconcile later, never resubmit
}
poll(id, firstAfter: 15s, every: 60s, maxPolls: 75)Cost
DataForSEO's published Standard-queue prices on 23 November 2026: Google Organic $0.0006 per SERP, plus the same again for the asynchronous AI Overview; Google AI Mode $0.0012 per task; LLM Scraper $0.0012 per result. Priority and Live modes cost more.[7][9][10]
Getting citations and mentions out of the response
AI Overviews and AI Mode. Find the item with type: 'ai_overview' in result[0].items. No such item means Google showed no overview: record that as an observation, not an error. Inside it, walk the elements (ai_overview_element, ai_overview_expanded_element, table and video elements; AI Mode adds shopping and code-block elements), collecting their text and links. Citations are the references on the block and its elements, deduplicated by URL. In AI Mode, skip ai_overview_paid elements: they are ads, not answer text or citations.
overview = items.find((i) => i.type === 'ai_overview');
if (!overview) return { present: false };
answerElements = walk(overview, skip: ["ai_overview_paid"]) // drops ads and their children
text = answerElements
.map((e) => e.text || e.title)
.dedupe()
.join('\n\n');
citations = [overview, ...answerElements].flatMap((e) => e.references).uniqueBy('url');ChatGPT and Gemini app answers. The result has markdown (the answer), sources (what the answer cited, also on nested items), search_results (everything the search returned, including pages the answer did not use), fan_out_queries (the searches the model ran) and brand_entities.[8] Take citations from sources, walking nested items. Store search_results as sources retrieved, kept apart from citations. When a response has no search_results array, record sources retrieved as unavailable, not as an empty list. DataForSEO documents the field for ChatGPT; check the Gemini response before you rely on it. Skip any item of type chat_gpt_ad in all of them, because it is a paid placement. CiteLadder keeps brand_entities as raw evidence and runs its own matcher, so every engine is counted by the same rule.
Mention and citation detection
Brand mentions
- Normalise both sides. Case-fold, normalise Unicode and whitespace. Languages written without spaces, such as Chinese, Japanese and Thai, need word segmentation first.
- Match whole words. "Ace" must not match inside "Space".
- Use aliases. Each brand has a name and a list of aliases. A multi-word name can also match its joined form, so "Ace Hardware" matches "acehardware". Separate words in the answer never join to spell a name, so "your sales force" does not count as Salesforce unless you add that alias.
- Guard common words. A brand called "Notion" or "Apple" needs a context term nearby, such as a category word or a rival's name, before it counts. Add exclusion phrases for known false positives.
- Freeze the rules per run. If you edit an alias, old runs keep the rules they were scored with, and runs with different rules are not compared.
function mentioned(answer, brand) {
for (hit of wholeWordHits(normalise(answer), [brand.name, ...brand.aliases])) {
if (insideExclusion(hit, brand.exclusions)) continue;
if (brand.contextRequired && !nearby(hit, brand.contextTerms, window)) continue;
return true;
}
return false;
}Owned citations
Reduce each cited URL to its registrable domain with a public-suffix library, so blog.example.co.uk and example.co.uk match and example.co.uk.evil.com does not. Canonicalise the full URL as well (lowercase host, drop tracking parameters and fragments) so the same page counts once. Then classify each citation as owned, competitor or other by comparing the domain with the brand's and each competitor's domains.
Position, share of voice and win rate
- Visibility (mention rate): answers naming the brand ÷ successful answers.
- Citation rate: answers citing an owned URL ÷ successful answers.
- Position: the brand's order of first mention among tracked brands in that answer. It is undefined when the brand is not named, so do not record it as last.
- Share of voice: the brand's mentions ÷ mentions of all tracked brands.
- Win rate: answers where the brand is named first among tracked brands ÷ answers naming any tracked brand.
Failed, unavailable and observed-zero must stay three different states. A timed-out answer is not an answer that ignored you. For more on what rank means inside an answer, see the LLM rank tracker guide.
Everything else a home-built tracker needs
A prompt set. Write questions a buyer would type, mostly without your brand name, grouped by topic and buying stage. Keep each prompt short; CiteLadder caps tracked prompts at 300 characters. Version the set, because changing a prompt starts a new series.
Repetition. The same prompt returns different answers. Run each prompt several times per engine and report "2 of 3" next to the rate. CiteLadder allows 1 to 10 repetitions and defaults to 3.[1]
Markets. A measurement market is a country plus a language. Pass it to the model APIs through user_location and to DataForSEO through location_code and language_code. A prompt that names Sydney is still measured from wherever you set the market.
Scheduling and a queue. Run each answer as its own task with a lease and a retry count, so a crash does not lose or duplicate paid work. A PostgreSQL table with row locks is enough; CiteLadder uses no separate queue server. Retry empty and unfinished answers, but not content-filter refusals.
Storage. Keep the raw response, the parsed record and the derived metrics separately, and never overwrite an answer. When your parser improves, re-derive metrics from stored responses without calling the provider again.
Comparability. Give each run a key built from the engine, model, web search setting, prompt version, market and matching rules. Only runs with the same key form a trend. A model change should break the line on the chart.
Cost control.
- Estimate before you run: prompts × engines × repetitions × markets × price per call.
- Cap searches per answer (
max_tool_calls,max_uses) and output tokens. - Use DataForSEO's Standard queue for scheduled work.
- Detect an exhausted account: HTTP 400, 402 or 429 with
insufficient_quota,billing_erroror "credit balance is too low" in the body means stop calling that provider, not retry. - Rate-limit per provider, so one slow surface does not hold up the rest.
Monitoring. Log every attempt with its error class (timeout, rate limit, server error, auth failure, parse error). A parser error after a provider changes its response shape should alert you, not count as zero mentions.
Or use a tool
A home-built tracker needs ongoing maintenance, because providers change their APIs and response shapes. If you prefer not to maintain one:
- CiteLadder runs everything on this page, hosted or self-hosted under AGPL-3.0. The open-source guide shows how to run it with Docker, and the pricing page covers the hosted plans.
- Other open-source platforms make different trade-offs; the open-source AEO platform comparison covers OpenSEO, Elmo and Ansvisor.
Either way, keep your prompt list, competitor list and aliases in a plain file. That is the part of the work that carries over to any tool.
Frequently asked questions
Which AI APIs return citations?
OpenAI, Anthropic and Gemini all return citations when their web search tool is on. OpenAI and Gemini give character offsets into the answer; Anthropic gives the cited text. Without web search, none of them cites anything.
Is an API answer the same as the ChatGPT app?
Not necessarily. The app runs with its own settings, location and search behaviour, which an API call does not reproduce. Track the API and the app as separate surfaces, and label each one.
How do I track Google AI Overviews without scraping Google myself?
Use a SERP provider such as DataForSEO with load_async_ai_overview set to true, then read the ai_overview item and its references.
How many repetitions do I need?
Enough that one odd answer does not swing the rate. Three per prompt and engine is a common starting point; raise it for the prompts that matter most.
What does a home-built tracker cost to run?
Mostly provider fees: tokens and search fees for the model APIs, and per-task fees for DataForSEO. Multiply prompts × engines × repetitions × markets × runs per month by the per-call price before you schedule anything.
Skip the plumbing
CiteLadder runs the collection, parsing and comparison described on this page for ChatGPT, Claude, Gemini, Google AI Overviews, Google AI Mode, ChatGPT Search and the Gemini app, and keeps every number tied to its stored answer.