Python · langchain-serpkite
LangChain + SerpKite
Give a LangChain agent real-time Google search with the official langchain-serpkite package: a ready-made search tool, a retriever that returns Documents, and a loader that turns any URL into Markdown.
Overview
What LangChain is, and where SerpKite fits
LangChain is the most widely used Python framework for LLM apps and agents. langchain-serpkite is SerpKite's first-party integration package, built on the official serpkite Python SDK.
SerpKiteSearch returns the results page as compact Markdown, so the agent spends fewer tokens reading results. SerpKiteSearchResults returns a JSON list when you want structured rows, and SerpKiteRetriever returns Document objects for RAG chains.
Setup
Set it up in 4 steps
-
1
Get an API key
Sign up (no card), create a key in the dashboard and export it as
SERPKITE_API_KEY. New accounts get 2,500 free credits, then 1,000 every month.export SERPKITE_API_KEY=skt_live_… -
2
Install langchain-serpkite
Any chat model provider works; the example uses OpenAI.
pip install -U langchain-serpkite langchain langchain-openai -
3
Create the search tool
SerpKiteSearch()readsSERPKITE_API_KEYand returns Markdown the model can read directly. -
4
Create the agent and ask a question
Pass the tool to
create_agent. The model decides when to search.
Code
Complete example
from langchain.agents import create_agent
from langchain_serpkite import SerpKiteSearch
search = SerpKiteSearch() # reads SERPKITE_API_KEY, returns Markdown
agent = create_agent(
model="openai:gpt-5-mini",
tools=[search],
system_prompt="You are a research assistant. Search before answering and cite URLs.",
)
result = agent.invoke(
{"messages": [{"role": "user", "content": "Who won the most recent Tour de France?"}]}
)
print(result["messages"][-1].content)What's in the package
Tools, retriever and loader
-
SerpKiteSearcha tool that returns the results page as Markdown (results, People Also Ask, related searches). The best default for agents.
-
SerpKiteSearchResultsa tool that returns a JSON list of results (
title,link,snippet,position) when you need structured rows. -
SerpKiteRetriever(k=5, include_content=2)a retriever that returns
list[Document], optionally with full page content. -
SerpKiteWebpageLoader([urls])a document loader that reads any public URL as clean Markdown via
/v1/webpage. -
SerpKiteAPIWrapperthe underlying wrapper if you want to call the API from your own tool.
Go deeper
Let the agent read pages too
Search snippets are often not enough. Load full pages with SerpKiteWebpageLoader, or give the agent a second tool that reads a URL as Markdown (1 credit per page).
from langchain.agents import create_agent
from langchain_core.tools import tool
from langchain_serpkite import SerpKiteSearch, SerpKiteWebpageLoader
@tool
def read_webpage(url: str) -> str:
"""Fetch a public web page and return its main content as Markdown."""
docs = SerpKiteWebpageLoader([url]).load()
return docs[0].page_content if docs else "Could not read the page."
agent = create_agent(model="openai:gpt-5-mini", tools=[SerpKiteSearch(), read_webpage])AI assistants
Ask ChatGPT, Gemini and other AI assistants
The serpkite SDK asks ChatGPT, Gemini, Copilot Search, Google AI Mode and Brave's AI answer as a logged-out visitor (sk.chatgpt, sk.gemini, sk.copilot, sk.ai_mode, sk.brave_ai) and returns the answer as Markdown with the sources it cited. Wrap a method with @tool and add it next to the search tool. Give the agent a second opinion, or have it check what assistants say about your brand: track adds mentions of the brands and domains you list. See AI assistants.
ChatGPT 4, Gemini 3, Copilot Search 3, Google AI Mode 2 and Brave AI 2 credits per answer; failed, refused and empty answers are free. Brave answers in 1–10 s, ChatGPT in 10–30 s and Gemini in 5–30 s, so allow at least 120 seconds per call.
from langchain.agents import create_agent
from langchain_core.tools import tool
from langchain_serpkite import SerpKiteSearch
from serpkite import SerpKite, SerpKiteError
sk = SerpKite() # reads SERPKITE_API_KEY
@tool
def ask_chatgpt(prompt: str) -> str:
"""Ask ChatGPT (logged out, searching the web) and return its answer as Markdown
with the sources it cited. Use it to see what ChatGPT tells people. Takes 10–30 s."""
try:
return sk.chatgpt(prompt=prompt, format="markdown")
except SerpKiteError as e:
return f"ChatGPT failed: {e.message}"
agent = create_agent(model="openai:gpt-5-mini", tools=[SerpKiteSearch(), ask_chatgpt])FAQ
LangChain and SerpKite: common questions
Keep exploring
Related APIs and integrations
Start building
Give your LangChain project Google search
2,500 free credits, then 1,000 every month. No credit card.