Your LangChain agent can search the web, call LLMs, and query databases. But there's one thing it can't do: pay for things. Until now.
@minia2a/langchain gives your LangChain agents access to 299+ live x402 APIs — crypto data, web scraping, CAPTCHA solving, AI inference, and more — with 15 free trials per endpoint and automatic USDC payments when trials run out.
In this tutorial, you'll go from zero to a paying LangChain agent in 5 minutes.
A LangChain agent that can:
npm install @minia2a/langchain zod @langchain/core @langchain/openai
Three packages: the @minia2a/langchain toolkit, zod for schema validation (peer dependency), and LangChain core + your LLM of choice.
import { Minia2aToolkit } from "@minia2a/langchain";
const toolkit = new Minia2aToolkit({
config: {
autoTrial: true, // Use 15 free trials per endpoint
maxPricePerCall: 0.05, // Max $0.05 per paid call (optional)
}
});
That's it. autoTrial: true means your agent gets 15 free calls to every endpoint on the marketplace — no wallet, no USDC, no setup.
import { ChatOpenAI } from "@langchain/openai";
import { AgentExecutor, createOpenAIFunctionsAgent } from "langchain/agents";
import { ChatPromptTemplate } from "@langchain/core/prompts";
const llm = new ChatOpenAI({ model: "gpt-4o" });
const prompt = ChatPromptTemplate.fromMessages([
["system", `You are a helpful agent with access to the minia2a API marketplace.
Use search_minia2a_apis to find services by keyword.
Use call_minia2a_api to try them (auto-trial: 15 free calls each).
Use list_popular_minia2a_apis to see what's trending.
Always try an endpoint before reporting results — don't guess.`],
["human", "{input}"],
["placeholder", "{agent_scratchpad}"],
]);
const agent = await createOpenAIAccountFunctionsAgent({
llm,
tools: toolkit.getTools(),
prompt,
});
const executor = new AgentExecutor({
agent,
tools: toolkit.getTools(),
verbose: true,
});
// Ask about crypto
const result1 = await executor.invoke({
input: "What's the current Ethereum gas price? Find and use a gas API."
});
console.log(result1.output);
// → "The current Ethereum gas price is 12 gwei (low), 18 gwei (average),
// 25 gwei (high). Data from minia2a /x402/gas endpoint."
// Scrape a website
const result2 = await executor.invoke({
input: "Scrape the headline from news.ycombinator.com"
});
console.log(result2.output);
// → "The top story on Hacker News right now is..."
// Discover trending APIs
const result3 = await executor.invoke({
input: "What are the most popular APIs on minia2a right now?"
});
console.log(result3.output);
// → "The most popular APIs are: CAPTCHA solving (1,240 trials),
// web recall/search (1,134 trials), gas prices (648 trials)..."
| Tool | What It Does | Example |
|---|---|---|
search_minia2a_apis | Search 299+ APIs by keyword or category | "Find web scraping APIs" |
call_minia2a_api | Call any endpoint with auto-trial + payment | Call /x402/gas for gas prices |
list_popular_minia2a_apis | Browse trending and popular services | "What's trending?" |
Every endpoint on minia2a offers 15 free trial calls. No wallet needed. No signup. The toolkit handles this automatically:
call_minia2a_api with an endpoint pathHTTP 402 Payment Required with price + wallet addressmaxPricePerCall > 0 and configured a wallet → payment auto-handled via x402Real data: Across 9,000+ trials on minia2a, the top 10 endpoints capture 54% of all activity. The most popular are CAPTCHA solving, web recall/search, on-chain data lookup, and gas price APIs — exactly the kind of infrastructure tools agents need.
When you're ready to go beyond free trials, add a wallet:
import { Minia2aToolkit } from "@minia2a/langchain";
const toolkit = new Minia2aToolkit({
config: {
autoTrial: true,
maxPricePerCall: 0.10, // Willing to pay up to $0.10/call
},
wallet: {
privateKey: process.env.AGENT_PRIVATE_KEY, // Base wallet with USDC
// Or use Cloudflare Wallets / Coinbase SDK
}
});
The payment flow is fully automated:
402 Payment RequiredmaxPricePerCallThe toolkit works natively with LangGraph:
import { StateGraph, MessagesAnnotation } from "@langchain/langgraph";
import { ToolNode } from "@langchain/langgraph/prebuilt";
import { Minia2aToolkit } from "@minia2a/langchain";
const toolkit = new Minia2aToolkit();
const tools = toolkit.getTools();
const toolNode = new ToolNode(tools);
const graph = new StateGraph(MessagesAnnotation)
.addNode("agent", agentNode)
.addNode("tools", toolNode)
.addEdge("__start__", "agent")
.addConditionalEdges("agent", shouldContinue)
.addEdge("tools", "agent")
.compile();
// Stream agent decisions
for await (const chunk of await graph.stream({
messages: [{ role: "user", content: "Find and use a CAPTCHA solver" }]
})) {
console.log(chunk);
}
Here's what developers are actually building with agent+marketplace combinations:
The agent economy is moving from "one agent, one API key" to "one agent, one wallet, any API." The x402 protocol — now under the Linux Foundation with 40+ member organizations including Visa, Mastercard, Stripe, Google, and Cloudflare — makes this possible. @minia2a/langchain is the bridge between LangChain agents and this new economy.
No more API key management. No more subscription overhead. Agents pay for what they use, when they use it.
npm install @minia2a/langchain