Skip to main content
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 call anyapi_get_api before the first anyapi_run_api on an API.

Install

The package depends on langchain-core, not on langchain itself. Install langchain alongside it if you want the create_agent helper used below.

Authenticate

Set ANYAPI_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.
The client is built on first use, so importing the package and constructing a tool need neither a key nor a network connection. A missing key surfaces only when a tool is actually called. Alongside 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 LangChain BaseTool, so you can invoke it directly or bind a subset to your own model.

Tools

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.
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.
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.
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.
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. Use ainvoke anywhere you would use invoke.

Errors

A failed call returns a readable payload rather than aborting the agent’s run. The payload carries error 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.
Not using LangChain? The same loop is available over the MCP server, through the typed Python and TypeScript SDKs, and as an agent skill. Need help? Reach out at support@getanyapi.com.