microtoll

microtoll

For BuildersAPI ProvidersDiscover APIs
Guides

/

Haystack

Microtoll + Haystack

Pay-per-use APIs for your Haystack pipelines

Deepset's Haystack provides production-ready NLP pipelines with agent capabilities. Microtoll adds paid API tools to your Haystack agents.

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 Haystack

Haystack supports MCP tools via haystack-experimental.

Add Microtoll as a tool provider in your pipeline.

from haystack_experimental.components.tools.mcp import (
    MCPClientTool, StdioClientTransport
)

transport = StdioClientTransport(
    command="uvx",
    args=["microtoll-mcp"],
    env={"SPARK_MNEMONIC": "your-24-word-mnemonic"},
)

# Create tools from MCP server
tools = await MCPClientTool.from_server(transport)

# Use in a Haystack pipeline with ToolInvoker
from haystack.components.agents import Agent
agent = Agent(tools=tools, chat_generator=generator)
result = agent.run(
    messages=[{"role": "user", "content": "Search the web for Haystack vs LangChain"}]
)

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 →