Skip to main content


This page covers how to use the SearchApi Google Search API within LangChain. SearchApi is a real-time SERP API for easy SERP scraping.


  • Go to to sign up for a free account
  • Get the api key and set it as an environment variable (SEARCHAPI_API_KEY)



There is a SearchApiAPIWrapper utility which wraps this API. To import this utility:

from langchain_community.utilities import SearchApiAPIWrapper

API Reference:

You can use it as part of a Self Ask chain:

from langchain_community.utilities import SearchApiAPIWrapper
from langchain_openai import OpenAI
from langchain.agents import initialize_agent, Tool
from langchain.agents import AgentType

import os

os.environ["SEARCHAPI_API_KEY"] = ""
os.environ['OPENAI_API_KEY'] = ""

llm = OpenAI(temperature=0)
search = SearchApiAPIWrapper()
tools = [
name="Intermediate Answer",,
description="useful for when you need to ask with search"

self_ask_with_search = initialize_agent(tools, llm, agent=AgentType.SELF_ASK_WITH_SEARCH, verbose=True)"Who lived longer: Plato, Socrates, or Aristotle?")


> Entering new AgentExecutor chain...
Follow up: How old was Plato when he died?
Intermediate answer: eighty
Follow up: How old was Socrates when he died?
Intermediate answer: | Socrates |
| -------- |
| Born | c. 470 BC Deme Alopece, Athens |
| Died | 399 BC (aged approximately 71) Athens |
| Cause of death | Execution by forced suicide by poisoning |
| Spouse(s) | Xanthippe, Myrto |

Follow up: How old was Aristotle when he died?
Intermediate answer: 62 years
So the final answer is: Plato

> Finished chain.


You can also easily load this wrapper as a Tool (to use with an Agent). You can do this with:

from langchain.agents import load_tools
tools = load_tools(["searchapi"])

API Reference:

For more information on tools, see this page.

Help us out by providing feedback on this documentation page: