Skip to main content

Google's Custom Search API ends on 1 January. A drop-in cse.list replacement in Python and Node

Find every Custom Search call, map Google's parameters, and swap in a function that returns the same items in Python, Node or cURL.

Updated 9 min readMarkdown
Google's Custom Search API ends on 1 January. A drop-in cse.list replacement in Python and Node

Google's Custom Search JSON API stops on 1 January 2027, and it stopped taking new customers a while ago. I work on the search side of MeshArc, so I wrote the replacement I'd want if my own code still called customsearch.googleapis.com: a function that takes cse.list's parameters and hands back Google's items, so nothing upstream has to change. Below are the checklist, the code in Python, Node and cURL, and what a test run against it looked like, warts included.

What stops, and when

Custom Search JSON API Value (Google's overview page, checked 25 November 2026)
Free queries 100 a day
Paid queries $5 per 1,000
Daily ceiling 10,000 queries
Results a query can reach 100 (num is 1 to 10, and start + num can't pass 100)
New sign-ups Closed
After 1 January 2027 Discontinued

Google hasn't documented what the API will return after the cut-off. So treat any non-200 answer from customsearch.googleapis.com as a failure and alert on it, starting now.

Most calls do one of two jobs, and they need different replacements:

  1. Whole-web search. An app or an agent asks what the web says about something and reads the ranked links. You need another search API.
  2. Searching your own site. An engine restricted to your help centre or docs. You don't need a web search API for this at all. You need an index of your own pages.

Google's own way out, from its Programmable Search Engine blog (20 January 2026): the free Search Element widget with "Sites to search" for a search box on your own site, Vertex AI Search for up to 50 domains inside an app, and a full web search product you have to contact Google about.

The checklist

  1. Find every call. Search code and config for customsearch.googleapis.com, googleapis.com/customsearch, cse().list and the environment variables that hold the cx engine ID. Cron jobs and no-code automations count too.
  2. Sort each call into whole-web or own-site. The engine's settings in the Programmable Search control panel show which sites it covers.
  3. Map the parameters (the function below does it) and write down any you use that have no equivalent.
  4. Run old and new side by side on 20 queries your users really send, while the Google key still works, and compare the top ten.
  5. Decide what an empty answer does before it happens in production.
  6. Cut over, then delete the Google key before the end of December.

Step 4 is the one people skip, and it's the only one with a deadline baked in: the comparison stops being possible the day Google's key stops answering.

A drop-in replacement for cse.list

This takes the parameters you pass to Google and returns the parts of Google's response most code reads (items[].title, link, displayLink, snippet), so the code that calls it doesn't change. It doesn't fake the fields it can't fill: there's no searchInformation.totalResults and no pagemap.

pip install mesharc
# MeshArc as a stand-in for Google's cse.list. Needs MESHARC_API_KEY in the environment.
from urllib.parse import urlparse
from mesharc import MeshArc

arc = MeshArc()

def _freshness(date_restrict):
    """Google's d7, w2, m3, y1 -> the smallest MeshArc window that still covers it."""
    if not date_restrict:
        return None
    days = int(date_restrict[1:] or 1) * {"d": 1, "w": 7, "m": 31, "y": 366}[date_restrict[0]]
    for window, limit in (("day", 1), ("week", 7), ("month", 31), ("year", 366)):
        if days <= limit:
            return window
    return None  # longer than a year: no filter


def cse_list(q, num=10, start=1, siteSearch=None, siteSearchFilter="i",
             gl=None, hl=None, dateRestrict=None, **ignored):
    site = [siteSearch] if siteSearch else None
    res = arc.web_search(
        q,
        limit=10,
        page=(start - 1) // 10 + 1,       # start=11 is page 2
        country=gl,
        lang=hl,
        freshness=_freshness(dateRestrict),
        include_domains=site if siteSearchFilter == "i" else None,
        exclude_domains=site if siteSearchFilter == "e" else None,
    )
    # "blocked" with outcome "no_results": no results, nothing charged, so return no items like Google.
    # "blocked" with any other outcome: the search did not run (out of credits?), so raise, never "no results".
    if res.get("status") == "blocked":
        if res.get("outcome") != "no_results":
            raise RuntimeError("MeshArc search did not run (out of credits?)")
        hits = []
    else:
        hits = res.get("data", [])
    # MeshArc pages are fixed blocks of 10, like Google's start=1, 11, 21
    hits = hits[(start - 1) % 10 :][:num]
    return {
        "kind": "customsearch#search",
        "items": [
            {
                "kind": "customsearch#result",
                "title": h["title"],
                "link": h["url"],
                "displayLink": urlparse(h["url"]).netloc,
                "snippet": h.get("snippet", ""),
            }
            for h in hits
        ],
    }

Three behaviours to know. start doesn't have to be 1, 11 or 21: the function reads that block of ten and starts from start, but it doesn't cross into the next block, so start=5 returns results 5 to 10, not 5 to 14. Crossing over would mean a second search, so it stops at the block's end. dateRestrict rounds up to the next window MeshArc has, so d3 becomes the last week and you may see a few older results, never fewer. And cx, searchType and the other Google-only parameters land in ignored.

The same function in Node (the mesharc package on npm, ESM):

// npm install mesharc   (MESHARC_API_KEY in the environment)
import { MeshArc } from 'mesharc';

const arc = new MeshArc();

function freshness(dateRestrict) {
  if (!dateRestrict) return undefined;
  const per = { d: 1, w: 7, m: 31, y: 366 }[dateRestrict[0]];
  const days = (parseInt(dateRestrict.slice(1), 10) || 1) * per;
  for (const [window, limit] of [['day', 1], ['week', 7], ['month', 31], ['year', 366]]) {
    if (days <= limit) return window;
  }
  return undefined;
}

export async function cseList({ q, num = 10, start = 1, siteSearch, siteSearchFilter = 'i', gl, hl, dateRestrict }) {
  const opts = { limit: 10, page: Math.floor((start - 1) / 10) + 1 };
  if (gl) opts.country = gl;
  if (hl) opts.lang = hl;
  const window = freshness(dateRestrict);
  if (window) opts.freshness = window;
  if (siteSearch) opts[siteSearchFilter === 'e' ? 'excludeDomains' : 'includeDomains'] = [siteSearch];

  const res = await arc.webSearch(q, opts);
  // 'blocked' with outcome 'no_results': no results, nothing charged, so return no items like Google.
  // 'blocked' with any other outcome: the search did not run (out of credits?), so throw, never "no results".
  let hits;
  if (res.status === 'blocked') {
    if (res.outcome !== 'no_results') throw new Error('MeshArc search did not run (out of credits?)');
    hits = [];
  } else {
    hits = res.data ?? [];
  }
  // MeshArc pages are fixed blocks of 10, like Google's start=1, 11, 21
  hits = hits.slice((start - 1) % 10).slice(0, num);
  return {
    kind: 'customsearch#search',
    items: hits.map((h) => ({
      kind: 'customsearch#result',
      title: h.title,
      link: h.url,
      displayLink: new URL(h.url).hostname,
      snippet: h.snippet ?? '',
    })),
  };
}

And with cURL, for a shell script or a no-code tool. The request waits up to timeout seconds (120 at most). A slower search comes back with its id and a running status, and you read it again at GET /search/{id}.

curl -s https://api.mesharc.dev/api/v1/search \
  -H "Authorization: Bearer $MESHARC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"query": "http.client HTTPSConnection timeout", "limit": 10, "page": 1,
       "includeDomains": ["docs.python.org"], "timeout": 60}' \
| jq '{items: [.data[]? | {title, link: .url, snippet}]}'

What a test run showed

On 19 November 2026 we ran five searches through MeshArc's hosted MCP server, the same search the SDK calls. Four came back with 10 results each, one of them a repeat answered from cache. The fifth, a vague query restricted to docs.python.org, came back empty. Three things from that run are worth checking on your own queries:

  • Google answered none of the five. Each time it asked for JavaScript or refused, and DuckDuckGo's results were used. Since 24 November the response no longer says which engine answered, so if "Google's results" matters to your product, judge it on your 20 test queries.
  • A narrow domain filter on a vague query can return nothing. That's why both functions treat a no_results block as an empty answer and raise on anything else. An out-of-credits error that silently looks like "no results" is the kind of bug you find in March.
  • The two site-restricted searches took over 40 seconds and came back as jobs to poll. The SDKs poll for you, but if a person is waiting on the answer, a dedicated SERP API is the better fit.

Custom Search also still beats this switch in two places: 100 free queries a day, and image search (searchType=image). MeshArc returns web and news results only.

If you were searching your own site

An engine pointed at your own domain is a site search, and a web search API with a domain filter is a poor stand-in for it, as the empty result above shows. If people search from a box on your site, Google's free Search Element with "Sites to search" may be all you need. If an app or an agent searches your pages through an API, index the pages yourself:

project = arc.projects.create("https://help.example.com", name="Help centre", schedule="daily")
arc.runs.start(project["id"], wait=True)
hits = arc.search(project["id"], '"refund policy"')   # pages that say it, from the last run

Every run also tells you which pages were added, changed or removed, which a search index on its own never did.

If you want to see what comes back for your own queries before touching code, try a search in the playground (it asks you to sign in). The web search API page lists what a search returns.

Your turn

If you're still on Custom Search: what are you moving to, and which parameter turned out hardest to map? My guess is dateRestrict: "the last 3 days" has no exact match in the function above, so it rounds up to a week.


Originally published on mesharc.dev.

About the author

  • Building MeshArc, a scraping API for sites you re-crawl. I write about scraping, keeping RAG data fresh and spotting what changed on a site.

No comments yet. Be the first to comment.