Home › Docs › Adapters › LlamaIndex
LlamaIndex Adapter
agent402-llamaindexFunctionTool instances for LlamaIndex TS agents and workflows, built from the catalog's JSON Schema.
Install
npm install llamaindex @llamaindex/workflow @llamaindex/openai agent402-llamaindex @x402/fetch @x402/core @x402/evm viem
Quick start
import { agent } from "@llamaindex/workflow";
import { openai } from "@llamaindex/openai";
import { agent402Tools } from "agent402-llamaindex";
import { wrapFetchWithPayment } from "@x402/fetch";
import { x402Client } from "@x402/core/client";
import { registerExactEvmScheme } from "@x402/evm/exact/client";
import { privateKeyToAccount } from "viem/accounts";
const payClient = new x402Client();
registerExactEvmScheme(payClient, { signer: privateKeyToAccount(process.env.AGENT_KEY) });
const payFetch = wrapFetchWithPayment(fetch, payClient);
// web search, then a cited answer: both paid per call from the wallet
const { tools } = await agent402Tools({ slugs: ["search", "answer"], freeOnly: false, fetch: payFetch });
const myAgent = agent({ tools, llm: openai({ model: "gpt-4o-mini" }) });
const res = await myAgent.run("Search the web for x402 payment protocol adoption, then answer with citations: what is the x402 payment protocol?");
console.log(res.data.result);
No wallet yet? The pure-CPU tools (hash, uuid, base64, markdown, JSON and more) run free with proof-of-work and no wallet:
// free tier: every tool listed here is compute-payable (proof-of-work, no wallet)
const { tools } = await agent402Tools({ slugs: ["hash", "markdown-to-html", "text-stats", "uuid"] });
Configuration
| Option | Type | Description |
|---|---|---|
slugs |
string[] |
Load only these tools (a short list gives the model better tool selection). |
freeOnly |
boolean |
Default true: keep only compute-payable tools, paid with proof-of-work. Set false to include wallet-only tools. |
fetch |
typeof fetch |
A payment-wrapped fetch (@x402/fetch for x402, mppx for MPP) that pays wallet-only tools. |
baseUrl |
string |
Point to a self-hosted Agent402 instance. |
// Load only these tools (a short list gives the model better tool selection).
agent402Tools({ slugs: ["hash", "markdown-to-html"] })
// Default true: keep only compute-payable tools, paid with proof-of-work. Set false to include wallet-only tools.
agent402Tools({ slugs: ["extract", "hash"], freeOnly: false, fetch: payFetch })
// A payment-wrapped fetch (@x402/fetch for x402, mppx for MPP) that pays wallet-only tools.
agent402Tools({ freeOnly: false, fetch: payFetch })
// Point to a self-hosted Agent402 instance.
agent402Tools({ baseUrl: "https://my-agent402.example.com" })
Works with
LlamaIndex TS
@llamaindex/workflow agent()
FunctionTool