How to Set Up ThorData with LangChain
Set up Thordata with LangChain to fetch real-time SERP data and use structured search results inside AI applications.
Integrate ThorData with LangChain to provide LLM-based agents with reliable, anonymous, and scalable web access for executing real-world data tasks, covering 190 countries and regions.
You can use the langchain-thordata Python package to implement this integration, which supports the following features:
ThorSerpTool – ThorData offers a powerful SERP API that allows you to query search engines (Google, Bing, Yandex, DuckDuckGo) using geolocation and advanced customization options—features particularly useful for AI agents requiring real-time web information.
Alternatively, via ThorData's MCP (Model Context Protocol)—a local server providing various scraping and automation tools — Although it is not part of the langchain-thordata package, it can be manually integrated using LangChain's Tool or RequestsWrapper.
How to integrate ThorData with LangChain
Get your ThorData API Token
Log in to your ThorData dashboard.
Go to SERP API > API Token. If you haven't generated an API token yet, please generate one.
Install the ThorData integration
Run the following command to install the ThorData integration package for LangChain:
pip install langchain-thordataSet environment variables
Set your ThorData API Token as an environment variable:
import os
os.environ["THOR_API_KEY"] = "your-token"Using the ThorData + LangChain integration
API Reference: SERP API Documentation
Basic Usage
from langchain_thordata import ThorSerpTool
search_tool = ThorSerpTool.from_env()
result = search_tool.invoke({
"query": "LangChain tutorial",
"engine": "google",
"params": {
"gl": "us",
"hl": "en",
"device": "desktop",
},
})
print(result)Use within an Agent
from langchain_thordata import ThorSerpTool
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(model="gpt-4o-mini", temperature=0)
tool = ThorSerpTool.from_env()
# Tool calling without langchain_classic agents
model_with_tools = llm.bind_tools([tool])
response = model_with_tools.invoke("Search for the latest LangChain news")
print(response)Last updated
Was this helpful?