Skip to content

About

LangChain tools for API.SH, which turns public web pages from around 1,000 websites into clean JSON: search engines, social media, e-commerce, real estate, jobs, travel, news and sports (Google, Amazon, TikTok, Zillow, LinkedIn and more).

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

Repository files navigation

langchain-apish

LangChain tools for API.SH. API.SH turns public web pages from around 1,000 websites into clean JSON: search engines, social media, e-commerce, real estate, jobs, travel, news and sports (Google, Amazon, TikTok, Zillow, LinkedIn and more). With this package an agent can find the right endpoint and call it.

pip install -U langchain-apish
export APISH_API_KEY="..."        # https://app.api.sh/keys

Every account gets free monthly credits. Failed calls are free and there are no rate limits.

Tools

Tool What it does
ApishSearchTool (apish_search) Finds endpoints by keywords: route, what it returns, parameters, price. Free, needs no key
ApishCallTool (apish_call) Runs any endpoint (route + params) and returns its JSON
ApishTool(route=...) One endpoint as a tool, with its parameters as typed, validated arguments
ApishToolkit apish_search + apish_call, plus one ApishTool per route you list

Two generic tools cover the whole catalog and keep the prompt short. When an agent only needs a few endpoints, give it typed tools instead: models fill typed arguments more reliably.

Agent example

create_agent builds a LangGraph agent that calls tools in a loop until it can answer:

from langchain.agents import create_agent
from langchain_apish import ApishToolkit

tools = ApishToolkit().get_tools()  # apish_search + apish_call
agent = create_agent("openai:gpt-5-mini", tools)

result = agent.invoke(
    {
        "messages": [
            {"role": "user", "content": "How many followers does NASA have on TikTok, and what are the top 3 posts on r/python right now?"}
        ]
    }
)
print(result["messages"][-1].content)

Install the model provider you use (pip install langchain langchain-openai, or any other chat model with tool calling). To limit the agent to fixed endpoints:

toolkit = ApishToolkit(
    routes=["/zillow/v1/search", "/zillow/v1/property"],
    include_generic=False,
)
agent = create_agent("openai:gpt-5-mini", toolkit.get_tools())

Calling a tool directly

from langchain_apish import ApishSearchTool, ApishTool

print(ApishSearchTool().invoke({"query": "tiktok profile", "limit": 3}))

profile = ApishTool(route="/tiktok/v1/profile")
print(profile.args)  # {'username': {...}}
print(profile.invoke({"username": "nasa"}))  # JSON text

As a tool call (what an agent sends), the result is a ToolMessage: content is the JSON text for the model, and artifact holds the parsed data with the request id and credits used:

msg = profile.invoke({"name": profile.name, "args": {"username": "nasa"}, "id": "1", "type": "tool_call"})
msg.artifact["data"]["followers"], msg.artifact["credits_used"], msg.artifact["request_id"]

Async

Every tool supports ainvoke, using the async client of apish-sdk:

hits = await ApishSearchTool().ainvoke({"query": "google search"})
page = await ApishTool(route="/google/v1/search").ainvoke({"q": "best running shoes", "country": "us"})

Options

All tools take api_key (default: APISH_API_KEY), client / async_client (your own apish.Apish / apish.AsyncApish), raw (default False: leave out the bulky raw source blocks), and max_chars (results longer than this are cut, with a note telling the model to ask for less, e.g. with the fields parameter). ApishToolkit passes them to every tool and shares one client between them.

API errors are returned to the model as the tool result (for example api.sh error 400: url is required), so it can fix its parameters and try again.

Relation to apish-sdk

This package is built on apish-sdk, the official Python client: it uses the SDK's clients, endpoint list and tool naming. apish-sdk also ships a small helper, apish.langchain.apish_tools; the same call works here and returns this package's tools:

from apish import Apish
from langchain_apish import apish_tools  # was: from apish.langchain import apish_tools

tools = apish_tools(Apish())

Endpoints released after the installed apish-sdk are found through the live catalog (https://api.api.sh/catalog, free) and their parameters are read from the platform's OpenAPI document.

Development

uv sync --group test --group lint
uv run pytest tests/unit_tests                      # offline, HTTP mocked
APISH_API_KEY=... uv run pytest tests/integration_tests   # live: a few calls, costs credits

Links

License

MIT

About

LangChain tools for API.SH, which turns public web pages from around 1,000 websites into clean JSON: search engines, social media, e-commerce, real estate, jobs, travel, news and sports (Google, Amazon, TikTok, Zillow, LinkedIn and more).

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages