microtoll

microtoll

For BuildersAPI ProvidersDiscover APIs
Guides

/

LangChain / LangGraph

Microtoll + LangChain / LangGraph

Pay-per-use APIs for your LangChain agents

LangChain and LangGraph provide composable chains and stateful agent graphs. Microtoll lets your agents call paid APIs without managing separate API keys or subscriptions.

What is Microtoll?

Microtoll is a pay-per-use API gateway for AI agents. Instead of managing separate API keys and subscriptions for every service, your agent accesses paid APIs through a single MCP server — web search, transcription, image generation, LLMs, and more.

You only pay for what you use. No monthly subscriptions, no per-API signups. One wallet, all APIs.

Step 1: Set up your wallet

Microtoll payments use Spark — a Bitcoin layer that enables instant, near-zero-fee micropayments. Think of it like a prepaid balance: you load funds once, and your agent spends fractions of a cent per API call.

Quick setup (2 minutes)

1.

Run

pip install microtoll && microtoll setup

2.

Choose option 1 (Spark wallet) — the wizard generates a wallet for you

3.

Add funds (see below), then set your secret key:

export SPARK_MNEMONIC="your 24 words here"

How to fund your wallet

Your wallet needs a small amount of funds (a few cents to a few dollars) to start calling APIs. Choose the option that matches your situation:

I've never used crypto before

No problem. Buy a small amount of Bitcoin on a service that supports Lightning withdrawals, then pay a Lightning invoice generated by your wallet. First-time setup requires identity verification (KYC) — allow 15-30 minutes. Once verified, future top-ups take under 2 minutes.

1.

Run:

microtoll fund --lightning 5000

(generates a Lightning invoice for 5000 sats ≈ $5)

2.

Sign up and buy $5-10 of Bitcoin on one of these services:

Strike

— US, EU, UK, 65+ countries — credit/debit card

Cash App

— US only — debit card

Mt Pelerin

— 171 countries, no KYC under $200 — credit/debit card

Coinbase

— 100+ countries — credit/debit card

3.

In the app, go to Send/Withdraw → paste the Lightning invoice from step 1 → confirm — done!

I have USDC (Solana, Base, or Arbitrum)

Bridge your USDC to Spark in one step:

1.

Get your Spark address:

microtoll fund --show-address

2.

Go to

joltz.io

— paste your address and send USDC

I already have a Lightning wallet (Phoenix, Alby, Strike, Cash App...)

Send sats directly to your Microtoll wallet:

1.

Run:

microtoll fund --lightning 1000

(to receive 1000 sats)

2.

Pay the displayed invoice from your wallet — done!

New to this? A quick glossary:

Wallet = a small program that holds your funds (like a prepaid account). Mnemonic = 24 secret words that are your wallet's password — keep them safe, never share them. Sats = the smallest unit of Bitcoin (1 sat = 0.00000001 BTC). Spark = the payment network Microtoll uses for instant transfers.

Alternative backends: LNbits (cloud Lightning wallet), NWC (Alby Hub), Phoenixd (self-hosted). Run microtoll setup to see all options.

Step 2: Install microtoll-mcp

pip install microtoll-mcp

Or use uvx (no install needed): uvx microtoll-mcp

Step 3: Configure MCP in LangChain

LangChain supports MCP tools via langchain-mcp-adapters.

Install the adapter and connect Microtoll as a tool provider.

from langchain_mcp_adapters.client import MultiServerMCPClient
from langgraph.prebuilt import create_react_agent
from langchain_openai import ChatOpenAI

async with MultiServerMCPClient({
    "microtoll": {
        "command": "uvx",
        "args": ["microtoll-mcp"],
        "env": {
            "SPARK_MNEMONIC": "your-24-word-mnemonic",
            "MICROTOLL_CONSUMER_TOKEN": "mct_...",  # optional, for Travel Rule services
        },
    }
}) as client:
    tools = client.get_tools()
    agent = create_react_agent(
        ChatOpenAI(model="gpt-4o"),
        tools,
    )
    result = await agent.ainvoke({
        "messages": "Search the web for AI agent payment solutions"
    })

Available tools

Once configured, your agent has access to these MCP tools:

search_apis

Discover APIs with pricing and health status

estimate_cost

Check the price before paying

call_api

Call any API — payment is automatic

get_wallet_status

Check wallet balance and credits

get_spending_history

View spending history and summary

check_health

Check API health before calling (free)

request_api

Request a new API to be added

identify_consumer

Register for Travel Rule compliance (one-time)

Step 4: Verify it works

Ask your agent to search for something. It should:

1.

Call search_apis to find the right API

2.

Call estimate_cost to check the price

3.

Call call_api to get results (payment is automatic)

Not using MCP? See SDK & direct integration options →