LlamaIndex TS
agent402-llamaindex · npm · MIT
Returns a FunctionTool[] array for any LlamaIndex TS agent or workflow, built from the catalog's raw JSON Schema, so there is no Zod or hand-written schema to maintain.
Install
npm install llamaindex agent402-llamaindex
Example
import { OpenAIAgent } from "llamaindex";
import { agent402Tools } from "agent402-llamaindex";
const { tools } = await agent402Tools({ slugs: ["extract", "hash", "render", "screenshot"] });
const agent = new OpenAIAgent({ tools });
const res = await agent.chat({ message: "Get the title of https://example.com/article" });
console.log(res.response);
What it exposes
- One native tool per catalog slug you pass in
slugs(a short list gives the model better tool selection). - With no
slugs, the free-tier catalog: every compute-payable tool (freeOnly: trueis the default). - An
execute(name, args)function that runs a tool call and pays for it underneath. baseUrlpoints the adapter at a self-hosted Agent402 instance.
How payment works
- Free tier: compute-payable tools settle with a sha256 proof-of-work solved in-process. No wallet, no API key.
- Wallet-only tools (browser, network, memory, live data): set
freeOnly: falseand pass a payment-wrappedfetch. An@x402/fetchfetch pays in USDC over x402; a stockmppxfetch pays over MPP. The same 402 carries both offers. - Prices come from the live catalog at /api/pricing and are quoted in every 402 before anything is signed.
const { tools } = await agent402Tools({
freeOnly: false,
fetch: payFetch, // your @x402/fetch-wrapped fetch
});
A call that fails is not charged: settlement runs after the tool and only on a successful response. Background: What x402 is · MPP (Machine Payments Protocol).
Tools to try first
Extract article$0.010
extract
Hash$0.001
hash
Browser render$0.02
render
Screenshot$0.004
screenshot
Markdown to HTML$0.001
markdown-to-html
Every tool, price and input schema: the catalog.
Links
agent402-llamaindex on npm · source on GitHub · configuration reference
Guides: Make your AI agent pay for what it needs: x402 in 5 minutes · Durable memory for AI agents - no accounts, the wallet is the identity
All integrations