Google's AI mode is changing search. The top 10 links is no longer the primary focus. AI mode - is the new "Page 1". This changes the requirement from ranking in the first 10 results to being cited in the AI answer. To win this Generative Engine Optimization (GEO) challenge, you need to be a citable source for AI - one that it can synthesize information from. The question becomes: How do you get cited in AI's answer, and how do you track that at scale?
It all starts with finding and tracking citations. In this blog post, I'll introduce a method of tracking citations using SerpApi's Google AI Mode API and a Python script I worked on to take a list of questions and automatically extract the "citation list", which you can use for your use case.
More About GEO
Generative engine optimization (GEO) is the practice of making content more visible and trustworthy for AI-powered search engines and chatbots, like Google's AI Overviews or ChatGPT. Unlike traditional SEO, which focuses on ranking individual links, GEO aims to have your content cited and featured within AI-generated answers and conversational responses. It involves creating high-quality, well-structured content that directly answers user questions, building brand authority, and ensuring best practices are in place.
Why Use SerpApi?
SerpApi streamlines the process of web-scraping. We take care of proxies and any CAPTCHAs that might be encountered, so that you don't have to worry about your searches being blocked. If you were to implement your own scraper using tools like BeautifulSoup and Requests, you'd need to determine your own solution for this. SerpApi manages the intricacies of scraping and returns structured JSON results. This allows you to save time and effort by avoiding the need to build your own Google scraper or rely on other web scraping tools.
We also do all the work to maintain all of our parsers and adapt them to respond to changes on Google's side. This is important, as Google is constantly experimenting with new layouts, new elements, and other changes. By taking care of this for you on our side, we eliminate a lot of time and complexity from your workflow.
SerpApi's Google AI Mode API
We recently released Google AI Mode API, which scrapes results from Google's AI Mode. This API makes it easy to retrieve Google AI Mode results programmatically, in a nested JSON format.
Let's take a look at how it works in the Playground, a convenient UI for testing out SerpApi's APIs with different search queries and parameters.
For example, let's try searching the Google AI Mode API with the query: "Compare shoes for running". Here's the example in our playground:
Here are what the references in the response look like:

Track Citations in References
To track AI mode citations for certain prompts, set this script to run every day at a particular time. This way you can monitor changes over time. You can add as many questions as you like, just note that the search credits will be used proportionally (1 per question).
Setup your environment
Ensure you have the necessary libraries installed.
pip install google-search-resultsgoogle-search-results is our Python library. You can use this library to scrape search results from any of SerpApi's APIs.More About Our Python Libraries
We have two separate Python libraries serpapi and google-search-results, and both work perfectly fine. However, serpapi is a new one, and all the examples you can find on our website are from the old one google-search-results. If you'd like to use our Python library with all the examples from our website, you should install the google-search-results module instead of serpapi.
For this blog post, I am using google-search-results because all of our documentation references this one.
You may encounter issues if you have both libraries installed at the same time. If you have the old library installed and want to proceed with using our new library, please follow these steps:
- Uninstall
google-search-resultsmodule from your environment. - Make sure that neither
serpapinorgoogle-search-resultsare installed at that stage. - Install
serpapimodule, for example with the following command if you're usingpip:pip install serpapi
Get your SerpApi API key
To begin scraping data, first, create a free account on serpapi.com. You'll receive 250 free search credits each month to explore the API.
- Get your SerpApi API Key from this page.
- [Optional but Recommended] Set your API key in an environment variable, instead of directly pasting it in the code. Refer here to understand more about using environment variables. For this tutorial, I have saved the API key in an environment variable named "SERPAPI_API_KEY" in my .env file.
Track Citations Using Google AI Mode API
First, we'll write a simple function to get citations from Google AI mode API:
from serpapi import GoogleSearch
from dotenv import load_dotenv
import os
load_dotenv()
def get_references_from_ai_mode(question):
params = {
"api_key": os.environ["SERPAPI_API_KEY"],
"engine": "google_ai_mode",
"q": question,
}
search = GoogleSearch(params)
results = search.get_dict()
return results.get("references", "")Then, we can make a list of questions we want to check our positions for:
# --- Main Execution ---
if __name__ == "__main__":
list_of_questions = [
"What are the best running shoes for beginners?",
"Running shoes vs walking shoes: what are the differences?",
"How to choose the right running shoes for flat feet?",
"What are the top-rated running shoes for long-distance running?",
"Are expensive running shoes worth the investment?",
"Top 20 running shoes",
"Best running shoes for trail running",
"How to properly care for running shoes?",
"What are the latest innovations in running shoe technology?",
"How do running shoes impact overall running performance?"
]
your_website_domain = "nike.com" # Replace with your actual domain
for question in list_of_questions:
references = get_references_from_ai_mode(question)
if not references:
print("No references are found for this question in AI mode:", question)
else:
print(f"Question: {question}")
position = -1
for ref in references:
if your_website_domain in ref.get('link', ''):
position = references.index(ref)
break
if position == -1:
print(f"Website domain '{your_website_domain}' not found in references.")
else:
print(f"Position of '{your_website_domain}' in references: {position}. (first position is 0)")
The Output
This prints each question and the position of your URL in the references output by the AI mode answer. If your URL was not found, you'll see "not found in references".
If the AI mode answer itself had no references returned, you'll see "No references are found for this question in AI mode".
Let's run the script with the domain "nike.com" and questions specified as follows:
your_website_domain = "nike.com"list_of_questions = [
"What are the best running shoes for beginners?",
"Running shoes vs walking shoes: what are the differences?",
"How to choose the right running shoes for flat feet?",
"What are the top-rated running shoes for long-distance running?",
"Are expensive running shoes worth the investment?",
"Top 20 running shoes",
"Best running shoes for trail running",
"How to properly care for running shoes?",
"What are the latest innovations in running shoe technology?",
"How do running shoes impact overall running performance?"
]The output is:

If you want to see a list of all the URLs listed as references for each question, add a print line like this inside the for loop:
print("- " , ref.get('link', '')
Here are what the results look like with this addition:

This makes it easy to analyze exactly what URLs were returned and which text parts got picked.
Let's store this data in a CSV now, so we can store it for any analysis you would want to do on it later.
Adding This Data to a CSV
To add this data to a CSV, let's make some modifications to add a header to the CSV and then add the data once we have extracted the links for each question.
Here's the updated code:
# --- Main Execution ---
if __name__ == "__main__":
# New addition for the header
header = ['Question', 'Domain', 'Position found', 'Links'] # Specify a list of the fields you are interested in
with open("google_ai_mode_citations.csv", "w", encoding="UTF8", newline="") as f:
writer = csv.writer(f)
writer.writerow(header)
list_of_questions = [
"What are the best running shoes for beginners?",
"Running shoes vs walking shoes: what are the differences?",
"How to choose the right running shoes for flat feet?",
"What are the top-rated running shoes for long-distance running?",
"Are expensive running shoes worth the investment?",
"Top 20 running shoes",
"Best running shoes for trail running",
"How to properly care for running shoes?",
"What are the latest innovations in running shoe technology?",
"How do running shoes impact overall running performance?"
]
your_website_domain = "nike.com"
for question in list_of_questions:
references = get_references_from_ai_mode(question)
if not references:
position = "Not Found"
links = "No references found"
else:
position = "Not Found"
links = []
for ref in references:
links.append(ref.get('link', ''))
if your_website_domain in ref.get('link', ''):
position = references.index(ref)
break
# New addition to write the links and position to CSV
with open("google_ai_mode_citations.csv", "a", encoding="UTF8", newline="") as f:
writer = csv.writer(f)
links = '\n'.join(links) # Join links with newline for better readability in CSV
writer.writerow([question, your_website_domain, position, links])Here are what the results look like:

Extensions to the Script
This is a tool to find which URLs appear for queries in AI mode, and help with Generative Engine Optimization using SerpApi.
This script can be expanded to run directly from a CSV file of 100s of questions using Google Sheets built in AppsScript. You can also store the results in a different database of your choice as well and track citation changes over time.
Adding a simple dashboard integration can also help visualize and graph the data on which domains are winning the most citations in your niche.
Conclusion
I hope this blog post was helpful in understanding how to you can write a simple script to measure how well you are doing in AI mode citations and keep up with the changing search landscape with Google's AI mode.
You can find all the code used in this blog post here:
If you have any questions, don't hesitate to reach out to me at sonika@serpapi.com.
Relevant Links
Documentation
Related Posts






