Microtoll + OpenAI Agents SDK
Pay-per-use APIs for OpenAI agents
The OpenAI Agents SDK (formerly Swarm) enables multi-agent workflows with tool use. Microtoll provides paid API tools your agents can call with automatic Spark payments.
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 setup2.
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:
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-addressI 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-mcpOr use uvx (no install needed): uvx microtoll-mcp
Step 3: Configure MCP in OpenAI Agents SDK
OpenAI Agents SDK supports MCP servers natively.
Register Microtoll as an MCP server in your agent configuration.
from agents import Agent
from agents.mcp import MCPServerStdio
microtoll = MCPServerStdio(
command="uvx",
args=["microtoll-mcp"],
env={"SPARK_MNEMONIC": "your-24-word-mnemonic"},
)
agent = Agent(
name="Researcher",
instructions="Use Microtoll tools to search the web and analyze data.",
mcp_servers=[microtoll],
)
# The agent can now call search_apis, call_api, estimate_cost, etc.
from agents import Runner
result = await Runner.run(
agent,
"Search for the latest AI payment solutions using Tavily"
)Available tools
Once configured, your agent has access to these MCP tools:
search_apisDiscover APIs with pricing and health status
estimate_costCheck the price before paying
call_apiCall any API — payment is automatic
get_wallet_statusCheck wallet balance and credits
get_spending_historyView spending history and summary
check_healthCheck API health before calling (free)
request_apiRequest a new API to be added
identify_consumerRegister 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 →