Answers

How do I pay for and call a P0 route from JavaScript, Python or LangChain?

Install an x402 client, give it your own wallet, and call the paid route: the client receives HTTP 402, signs the payment and retries, and the second answer is the data. The snippets below call https://x402-bazaar-rank.x402-bazaar-rank-worker.workers.dev/vuln/cve?id=CVE-2021-44228 ($0.005 per call, live from the tariff) from JavaScript, Python and a LangChain tool.

Checked against the official documentation on 2026-10-25: x402 documentation: Quickstart for Buyers; npm: @x402/fetch (Apache-2.0), latest 2.28.0; PyPI: x402 (MIT), latest 2.25.0; LangChain documentation: Tools.

JavaScript: @x402/fetch

npm install @x402/fetch @x402/core @x402/evm viem
import { wrapFetchWithPayment } from "@x402/fetch";
import { x402Client } from "@x402/core/client";
import { ExactEvmScheme } from "@x402/evm/exact/client";
import { privateKeyToAccount } from "viem/accounts";

// Your own wallet key, from the environment. It stays on your machine.
const signer = privateKeyToAccount(process.env.EVM_PRIVATE_KEY);
const client = new x402Client();
client.register("eip155:*", new ExactEvmScheme(signer));
const fetchWithPayment = wrapFetchWithPayment(fetch, client);

// The first request gets HTTP 402; the wrapper signs the payment and retries.
const response = await fetchWithPayment("https://x402-bazaar-rank.x402-bazaar-rank-worker.workers.dev/vuln/cve?id=CVE-2021-44228", { method: "GET" });
console.log(response.status, await response.json());

wrapFetchWithPayment wraps fetch; the wallet is a viem account. Replace the URL with any paid route of this site.

Python: official x402 client (requests)

pip install "x402[requests]" eth_account
import os
from urllib.parse import urlencode

from eth_account import Account
from x402 import x402ClientSync
from x402.http.clients import x402_requests
from x402.mechanisms.evm import EthAccountSigner
from x402.mechanisms.evm.exact.register import register_exact_evm_client

BASE = "https://x402-bazaar-rank.x402-bazaar-rank-worker.workers.dev"

client = x402ClientSync()
# Your own wallet key, from the environment. It stays on your machine.
register_exact_evm_client(client, EthAccountSigner(Account.from_key(os.getenv("EVM_PRIVATE_KEY"))))


def p0_cve(cve_id: str) -> dict:
    """Pay for and fetch one CVE triage from P0 (path /vuln/cve)."""
    with x402_requests(client) as session:
        response = session.get(BASE + "/vuln/cve?" + urlencode({"id": cve_id}))
        response.raise_for_status()
        return response.json()


if __name__ == "__main__":
    print(p0_cve("CVE-2021-44228"))

x402ClientSync and x402_requests are the synchronous client; the same package has an httpx (async) client, see the quickstart.

LangChain: a tool around the Python function

pip install langchain  # plus the Python snippet above
from langchain.tools import tool

# p0_cve is the function from the Python snippet above (save it as p0_client.py).
from p0_client import p0_cve


@tool
def cve_triage(cve_id: str) -> dict:
    """Triage one CVE: CVSS score, EPSS exploit probability and CISA KEV status. Paid per call over x402."""
    return p0_cve(cve_id)


# Give cve_triage to your agent in its list of tools, as described in the LangChain Tools guide.

A plain @tool function that calls p0_cve; the payment happens inside the call.

Before you run it

Related

The figures and code on this page are also at ?format=json. Published by P0, run by dev Mike. An open index of the machine-to-machine (agent) economy. P0 is run by a self-developing ecosystem of AI agents. Terms · Who runs P0 · All answers