LangChain Google Search after the Custom Search API shutdown (GoogleSearchAPIWrapper)
LangChain's GoogleSearchAPIWrapper (in langchain-google-community) calls Google's Custom Search JSON API through google-api-python-client. Google has closed that API to new customers and shuts it down on 1 January 2027. You can keep the wrapper and your agent code: build the same Google client against Google Custom Search API Alternative on Apify, which answers the same requests with the same JSON from live Google results, and give it to the wrapper as search_engine. Tested on 6 October 2026; searches cost $5 per 1,000, as Google charged.
Open Google Custom Search API Alternative on Apify $5 per 1,000 searches of up to 10 results ($4 on Gold and above)
Step by step
- Create a free Apify account. Sign up at apify.com and copy your API token from Settings → API & Integrations. The free plan's $5 monthly credit covers about 1,000 searches.
- Install the packages. pip install langchain-google-community google-api-python-client httplib2 (you probably have the first two already).
- Build Google's client against the drop-in. Call build("customsearch", "v1", developerKey="unused", http=…, client_options={"api_endpoint": "https://automationnation--google-custom-search-api.apify.actor"}, static_discovery=True), where the http object adds the header Authorization: Bearer YOUR_APIFY_TOKEN (code below).
- Hand it to the wrapper. Create GoogleSearchAPIWrapper(google_api_key="unused", google_cse_id="unused", k=5) and set search.search_engine to that client. run(), results() and the Tool you build from the wrapper work as before.
- Keep your agent as it is. Tools built from the wrapper (for example Tool(name="google_search", func=search.run)) need no changes.
- Mind the timeout. Each search fetches live Google results and takes about 4–10 seconds, so keep the client's timeout at 60 seconds.
Do it from code
Google's client, pointed at the drop-in
# pip install google-api-python-client httplib2 ; export APIFY_TOKEN=your_token
import os
import httplib2
from googleapiclient.discovery import build
class ApifyAuth(httplib2.Http):
"""Sends your Apify token with every request."""
def request(self, uri, method="GET", body=None, headers=None, *args, **kwargs):
headers = {**(headers or {}), "Authorization": f"Bearer {os.environ['APIFY_TOKEN']}"}
return super().request(uri, method, body, headers, *args, **kwargs)
service = build(
"customsearch", "v1",
developerKey="unused", # the Apify token in the header replaces the key
http=ApifyAuth(timeout=60),
client_options={"api_endpoint": "https://automationnation--google-custom-search-api.apify.actor"},
static_discovery=True, # bundled API description; nothing goes to Google
)
res = service.cse().list(q="best crm for startups", cx="unused", num=10).execute()
for item in res.get("items", []):
print(item["title"], item["link"])LangChain GoogleSearchAPIWrapper
# pip install langchain-google-community (plus the client above)
from langchain_google_community import GoogleSearchAPIWrapper
search = GoogleSearchAPIWrapper(google_api_key="unused", google_cse_id="unused", k=5)
search.search_engine = service # the client built above
print(search.run("how to learn rust"))
print(search.results("asyncio gather", 3))
From an AI assistant (MCP)
Add this MCP server URL to Claude, ChatGPT or Cursor and ask in plain English:
https://mcp.apify.com?tools=automationnation/google-custom-search-api
Alternatives
Other options: switch LangChain to a different search tool (Tavily, Brave Search, SerpAPI, Google Serper), each with its own API key, result format and prompts to retune; or Vertex AI Search, which Google suggests for searching up to 50 domains. The drop-in keeps Google's results and your existing wrapper.
FAQ
Does GoogleSearchAPIWrapper stop working on 1 January 2027?
Its default setup calls Google's Custom Search JSON API, which Google says existing customers must move off by 1 January 2027, and new customers can't sign up for it now. Pointed at a compatible endpoint, the wrapper keeps working.
Is my Apify token sent to Google?
No. With static_discovery=True the client reads the API description bundled with the library, and every request goes to the drop-in endpoint only.
Do I still need GOOGLE_API_KEY and GOOGLE_CSE_ID?
The wrapper requires values for them, but they aren't used; any placeholder works. To restrict results to your sites, add site: operators to the query or pass siteSearch in the wrapper's search parameters.
What does it cost?
$5 per 1,000 searches of up to 10 results ($4 on Gold and above), with no daily cap; searches that return nothing are free.
Written by AutomationNation, the developer of Google Custom Search API Alternative. Prices checked October 2026.