langchain-anyapi is the official LangChain integration for AnyAPI. It gives an agent
hundreds of data and scraping APIs through five tools, one key, and a wallet billed per
request in real US dollars.
Five tools, not one per API
AnyAPI publishes hundreds of APIs. Binding one tool per API would exhaust an agent’s context before it asked its first question, so this package teaches the loop instead: search or list to find an API, read its input schema, then run it. An agent that learns those five tools once can reach the entire catalog. Input schemas are strict. They reject unknown fields rather than ignoring them, so an input built from a description instead of a schema usually fails. Always callanyapi_get_api before the first anyapi_run_api on an API.
Install
The package depends onlangchain-core, not on langchain itself. Install langchain
alongside it if you want the create_agent helper used below.
Authenticate
SetANYAPI_API_KEY in the environment, or pass api_key= to the toolkit or to any
individual tool. Need a key? Create one in the dashboard,
or see the Quickstart.
api_key, every tool and the toolkit accept base_url, timeout, and
max_retries. Omit them to keep the SDK defaults.
Build an agent
AnyAPIToolkit().get_tools() returns all five tools, and ANYAPI_INSTRUCTIONS is a
system prompt that teaches the discover, inspect, run loop and its cost discipline.
Or call one tool at a time
Each tool is a plain LangChainBaseTool, so you can invoke it directly or bind a subset
to your own model.
Tools
anyapi_search_apis - find an API by intent
anyapi_search_apis - find an API by intent
Ranked search across the catalog, returning matches with their descriptions and
without their schemas. Never charges.
Returns
results, total, and ranking. Each result carries id, platform,
name, description, category, pricing, execution, and relevance.This tool requires query. The REST endpoint behind it also accepts category or
platform on their own, so reach for anyapi_list_apis when you want to enumerate a
category rather than search it.anyapi_list_apis - browse the catalog
anyapi_list_apis - browse the catalog
Browse APIs as lightweight summaries, optionally filtered by category. Descriptions
and schemas are omitted, so listing stays cheap in context. Never charges.
Returns
apis, an array of id, name, category, pricing, heavy, and
execution.anyapi_get_api - inspect one API
anyapi_get_api - inspect one API
Get one API in full, including the strict input schema you need to build a valid
payload. Never charges.
Returns the summary fields plus
description, provider, method, path,
inputSchema, outputSchema, lanes, and latency, which is null when there are
no successful observations to report.anyapi_run_api - execute an API
anyapi_run_api - execute an API
Execute one API with a normalized input payload. This is the only tool that touches
your wallet.
Returns
found, data, provider, costUsd, items, and resultId.fields, max_items, and summary are response-budget controls. They keep a large
result from flooding the context window and change only what comes back to you, never
what you are charged.anyapi_get_balance - check your wallet
anyapi_get_balance - check your wallet
Get the remaining wallet balance for the key you authenticate with. Takes no
arguments and never charges.Returns
usd, the remaining balance.Async
Every tool has a real async path built on the SDK’s async client, not the sync client on a worker thread. Useainvoke anywhere you would use invoke.
Errors
A failed call returns a readable payload rather than aborting the agent’s run. The payload carrieserror and status, plus code and requestId when the gateway sends
them. An agent can read that, adjust, and carry on within the same turn.
Calling a tool with no key resolves at call time and returns this, with nothing charged:
Prices
Prices come off the wire exactly as AnyAPI published them, and this package never recomputes one from another. Every static price is quoted twice:maxUsd is what one
request is billed, and maxPer1kUsd is the same price per 1,000 requests. Per 1,000 is
the denomination AnyAPI quotes customers in, because most of the catalog costs a fraction
of a cent per call.
There is no quote tool here. anyapi_get_api already publishes pricing.from.maxUsd,
the most a first-choice run is billed, and pricing.failoverMaxUsd, the ceiling for any
run, so an agent can bound its spend before it calls. A completed run reports its actual
charge as costUsd.