Skip to content

A LangChain tool that pays for its own call.

Wrap any endpoint on gateway.apiosk.com in a @tool your Python agent can call. The tool body makes one request; the 402, the USDC payment on Base and the retry all happen inside the session.

pip install "x402[requests,evm]" langchain-core

What you are about to do

The whole integration is one tool definition and one wallet key. Everything specific to LangChain is below; everything specific to payment happens inside the client.

Install x402 with the extras

01

pip install "x402[requests,evm]" langchain-core. The requests extra pulls in the sync HTTP path; the evm extra pulls in eth-account and web3, so x402[requests] alone fails at the Account import. Add langchain and langchain-anthropic when you wire up the agent.

Define the tool

02

Build the payment session once at module scope, then decorate a normal function with @tool. The body makes one request against gateway.apiosk.com; the 402, the signature and the retry happen inside session.get.

Hand it to create_agent

03

Pass the tool into create_agent alongside the model. From there the model decides when the job needs an FX rate or an email check, and the call is paid at the moment it is made.

LangChain, end to end

Copy these in order. The endpoints are placeholders. Swap in any endpoint from the catalog.

tools/convert_currency.pyPython
# tools/convert_currency.py
# pip install "x402[requests,evm]" langchain-core

import os

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

account = Account.from_key(os.environ["WALLET_PRIVATE_KEY"])

# x402ClientSync is the payment client, not an HTTP client. Register a signer
# against it, then hand it to x402_requests to get a requests.Session that
# answers the 402 on its own.
payments = x402ClientSync()
register_exact_evm_client(payments, EthAccountSigner(account))

session = x402_requests(payments)


@tool(parse_docstring=True)
def convert_currency(from_code: str, to_code: str, amount: float) -> dict:
    """Convert an amount between two currencies using live FX rates.

    Args:
        from_code: ISO currency code to convert from, e.g. EUR.
        to_code: ISO currency code to convert to, e.g. USD.
        amount: Amount to convert.
    """
    response = session.get(
        "https://gateway.apiosk.com/v1/fx/convert",
        params={"from": from_code, "to": to_code, "amount": amount},
        timeout=30,
    )
    response.raise_for_status()
    return response.json()
tools/verify_email.pyPython
# tools/verify_email.py

from langchain_core.tools import tool

# One payment-aware session for every tool. The wallet is built once, in
# tools/convert_currency.py.
from tools.convert_currency import session


@tool(parse_docstring=True)
def verify_email(email: str) -> dict:
    """Check whether an email address is deliverable.

    Args:
        email: The address to check, e.g. ada@example.com.
    """
    response = session.get(
        "https://gateway.apiosk.com/v1/email/verify",
        params={"email": email},
        timeout=30,
    )
    response.raise_for_status()
    return response.json()
agent.pyPython
# agent.py
# pip install langchain langchain-anthropic

from langchain.agents import create_agent

from tools.convert_currency import convert_currency
from tools.verify_email import verify_email

agent = create_agent(
    "anthropic:claude-opus-5",
    tools=[convert_currency, verify_email],
)

result = agent.invoke(
    {"messages": [{"role": "user", "content": "What is 250 EUR in USD right now?"}]}
)

print(result["messages"][-1].content)

Three things to know

The wallet stays in your process

The private key is read from the environment once, at import time, and lives in the module that builds the session. The agent never sees it and never handles a 402. From the model's side a paid call returns the same JSON any other tool would.

A sync tool needs the sync client

A @tool body is called synchronously, so use x402ClientSync with x402_requests. x402Client is the async client; the requests adapter raises TypeError if you hand it one. Build the session at module scope, not inside the tool, so a loop of calls reuses one connection pool.

The docstring is the tool spec

@tool(parse_docstring=True) parses a Google-style Args: block into per-argument descriptions, which is what the model reads when it fills in the call. One naming rule from langchain-core: do not call a tool argument config, run_manager, or callbacks. Those are reserved; take a ToolRuntime parameter if you need runtime access.

Good questions.

A few things to know before you start.

How pricing works
What is Apiosk?

Apiosk is AI-native compliance infrastructure. It gives your team and your AI agents one way to run compliance checks, such as company verification, beneficial ownership, sanctions screening and court records, against official sources. You ask in plain language, review the sources and maximum cost, approve, and get one sourced answer. Once, or on a schedule.

Which checks can I run?

Company profiles and filed accounts from business registers, beneficial ownership, sanctions and watchlist screening, court records, and identifier checks such as VAT numbers and IBANs. Coverage depends on the country and the source. If a source has no record, the result says what is missing rather than guessing.

Explore all checks
Does Apiosk make the compliance decision?

No. Apiosk retrieves the data, combines it and shows where every part came from. Assessing the result and deciding what to do with it stays with you and your compliance process.

How does ongoing monitoring work?

After your first result, choose Make recurring. Pick the days and time, and how much it may spend: a fixed number of prepaid runs, or pay as you go with a maximum per run. Apiosk repeats the check on that schedule and delivers every result, or only what changed, to Slack or Gmail. Each run and its cost stays visible in the order's history.

Can my AI agent run checks?

Yes. Apiosk is available as a connector for ChatGPT and Claude, and through MCP or API for other agents and tools. Authorize the agent once; your spending limits and approval rules control what it can run.

Connect an agent
How much does it cost?

Each check is priced from the sources it uses. Apiosk shows the sources and maximum cost, including its service fee, before anything runs, and recurring checks stay within the budget you approve. You pay from your Apiosk balance, with no subscription required.

See pricing
Which countries do you cover?

Company-register checks include the Netherlands and the United Kingdom. GLEIF legal-entity data and sanctions screening cover international records; VIES validates EU and Northern Ireland VAT numbers. Availability varies by company, filing and source. When a record is not available, we say so.

How does approval work for agents?

You set spending ceilings per request and per rolling day when you connect an agent. Checks need approval in the conversation or in Apiosk, unless you have explicitly authorized small runs in that conversation. A request above a connection limit is refused before it is charged; a person must review the limit in Apiosk before it can proceed.