Use this page to decide what each call costs and who gets it for free. Every option is a PaymentGate argument; the gate prices each call before it sends the 402, so the caller always sees the exact amount. Prices are integers in the base units of the gate’s asset: microALGO when asset_id=0, or the ASA’s base units (for USDC, 10-6 USDC). A price of 0 makes a call free and skips the challenge.

Fixed and per-tool prices

With only default_price, every tool costs the same.

Dynamic prices

Pass a callable instead of a dictionary. It receives the tool name, the call’s arguments and the caller’s verified address (None when the caller sent no valid identity proof), and returns the price.

Bulk discounts

With a ChainReader, the gate looks up how much the caller has paid to pay_to in a recent window. Above bulk_threshold, the price is multiplied by bulk_discount. The caller is identified by its identity proof.
ChainReader.for_network("testnet") creates a reader for a public network’s default indexer.

Example

This server (port 9202) has a dictionary price, a price per word, and a 50% discount above 10,000 microALGO of past spend. It makes three calls:
localnet/pricing.py
Source: examples/localnet/pricing.py
After two calls the buyer had paid 11,500 microALGO, above the threshold, so the third cost half of 6,000.

The fee floor

The server’s fee payer pays 2,000 microALGO per settled call (why). An ALGO price at or below that loses money on every call, so the gate guards against it:
  • A fixed price (prices dict or default_price) in 0 < price <= 2000 raises ConfigurationError (a ValueError) when the gate is created.
  • A price that lands in that range at call time (from a callable or after a discount) is raised to 2,001 microALGO, with a warning logged once per tool.
  • allow_loss=True turns both checks off, for deliberate subsidies.
  • The floor applies only when asset_id=0. USDC and other ASA prices are not compared with ALGO fees, although the server still pays the fees in ALGO.
3,000 microALGO is a sensible minimum ALGO price.

Passes

A pass lets a buyer pay once and then call your tools for free for pass_days (30 by default). How passes work. Passes need an indexer, because the gate finds them in the caller’s payment history.
Scope names are yours to choose. A pass counts only on gates whose pay_to received it, in the gate’s asset, and whose pass_scopes include its scope, so one vendor’s pass never unlocks another vendor’s tools. The note prefix is the constant PASS_NOTE_PREFIX (x402-pass:).

Buy a pass

Any wallet can buy one: send at least the scope’s price, in the gate’s asset, to pay_to with the note x402-pass:<scope>.
The buyer’s later calls must carry an identity proof; paid_mcp_session sends one by default.

Example

On port 9203, a buyer pays 5,000 microALGO for echo, buys a pass with the note x402-pass:listing:echo-1, waits for the indexer to see it, and calls again for free:
localnet/passes.py
Source: examples/localnet/passes.py

Subscription tokens

The gate can also treat holders of an ASA as subscribers. If the caller holds subscription_asset_id and received it within subscription_max_age_days, calls are free. Set subscription_issuer to count only tokens received from your own issuing account.

Order of evaluation

For each call, PaymentGate.price_for:
  1. Takes the base price from prices (dict or callable) or default_price.
  2. If it is 0, the call is free.
  3. If the caller holds a valid pass for one of pass_scopes, or a valid subscription token, the call is free.
  4. If the caller’s past spend is above bulk_threshold, applies bulk_discount.
  5. For ALGO prices, applies the fee floor.
Lookups that fail (indexer or algod errors) count as “no usage, subscription or pass”, and are logged.

Next