How to Charge AI Agents for API Usage with GOAT Flow

Nov 23, 2026

Share

Category /

other

12 min read

GOAT Network

How to Charge AI Agents for API Usage with GOAT Flow

Configure one fixed-price GOAT Flow API route, trace its ERC-20 transfer through verification, and recover a pending payment without paying twice.

scroll

Table of contents

Configure one fixed-price GOAT Flow API route, trace its ERC-20 transfer through verification, and recover a pending payment without paying twice.

Suppose your API generates a daily snapshot of a public product catalog. An agent needs one copy to update its index, and you want to charge a fixed amount for that request. GOAT Flow's paid API routes let you publish the price, have the agent pay your configured wallet directly, and protect your handler with a receipt. The implementation has two checkpoints. GOAT Flow Core has to verify the buyer's transfer, and your resource server has to validate the signed receipt before returning the snapshot.

Give the buyer a way to save the transaction hash as soon as the wallet returns it. A transfer can still be pending when the buyer's HTTP request ends. Keeping the original challenge and transfer reference lets the client resume verification instead of sending the price again.

The route and its four participants

Use a handler you already own. For this example, it serves one dated catalog snapshot at GET /api/docs/protected, the path used in GOAT Flow's Merchant Guide to illustrate route registration. One payment buys one request for the snapshot. Publish what the response contains and when the snapshot changes. Keep all requests on this example route at the same price. A route that starts a job whose cost depends on usage would need a different pricing and delivery design.

There are four participants at runtime.

  • The buyer agent reads the offer, checks the terms against its spending policy, and uses its wallet signer and chain RPC to broadcast. It submits payment evidence to Core, then presents the receipt to the seller. The public payment calls require no merchant API key.

  • The merchant resource server owns the URL that returns the snapshot. Its configured verifier checks the receipt at that URL and decides whether the handler can serve the request.

  • GOAT Flow Core issues a payment challenge for the route, verifies the on-chain transfer and its finality, and signs the receipt. The receiving address on the challenge belongs to the merchant's configuration.

  • The selected token network processes the buyer's ERC-20 transaction. The buyer's RPC is its interface to that network. A hash returned by the wallet gives the buyer a reference to check while Core applies its own verification rules.

A merchant Owner configures the offer in the Portal before that runtime exchange. The credential the Owner uses to administer the merchant, the wallet authorization used to pay, and the key material consumed by the seller's verifier have different jobs. Keep merchant credentials out of the buyer integration. Give the buyer enough information to identify the seller, the resource and the asset it is expected to spend.

Read the rest of the setup as GOAT Flow's current integration profile for Machine Payments Protocol (MPP). Standard MPP puts its payment challenge and credential retry on the protected-resource exchange. Common x402 client-server flows also retry the resource, carrying a payment payload such as PAYMENT-SIGNATURE in x402 v2, and can use a facilitator for verification and settlement. Here the public JSON challenge and verification calls happen separately from the merchant resource request. The buyer sends the transfer itself. Use a client that implements this GOAT-specific exchange and receipt format. The pinned guide reports no interoperability result with official MPP SDKs.

Publish the route with one eligible receiving pair

Start with the environment in which the agent will actually buy. In the Portal, a merchant Owner needs an enabled DIRECT merchant and access to Payment Setup > Paid API Routes (MPP). The status card should indicate that the routes are manageable. Check the active network and token selectors and confirm the merchant already has a receiving address for the pair. That receiving row matters even if another route accepts the same token name. Token contracts and receiving configuration are tied to the selected network.

  1. Define GET /api/docs/protected in the application. Mount the verifier on the handler before exposing the paid snapshot. Its route identifier is GET:api:docs:protected. The Portal uses the colon-delimited identifier for registration.

  2. In Receiving Tokens & Addresses, add or verify the row for the chosen network and token. Confirm who controls the receiving wallet and record the expected token contract and recipient for checking the configuration.

  3. In Paid API Routes (MPP), choose Add Route. Enter the exact canonical identifier, a configured version, the eligible network and token, and the fixed decimal amount. Save the row and confirm that it is active.

  4. Compare the saved row with the application and the receiving configuration. The HTTP method, route identifier, token contract, recipient, and amount should all describe the same sale. Then check the public route listing to confirm the route and current pricing version.

Use the amount, addresses, version value and eligible pair from the merchant's environment. If you cannot select the pair or manage the route, check the environment and merchant capability. The documented rail is an ERC-20 transfer, so the buyer needs the token balance and the native gas for the instructed network. Paid API Routes configuration.

Check the manifest and the three URLs

Keep three destinations in the integration notes. The merchant resource URL identifies where to fetch the catalog snapshot. A trusted merchant QuickPay link lets a manifest-driven client discover the offer. A configured Core/API origin identifies where a standalone client makes its challenge and verify calls. These URLs can have different origins. Using the merchant's API hostname for all three can send the request to the wrong service.

GOAT Flow documents the public agent entry and manifest under /paykit/<merchant_id>/agent.md and /paykit/<merchant_id>/manifest.json. On the trusted merchant surface, check that rails.mpp.enabled is true and that rails.mpp.routes contains the exact route_canonical you registered. Compare its route and pricing version with the active Portal row. If the manifest is missing the route or advertises a different version, resolve the discrepancy before asking the agent to approve a payment.

The QuickPay-driven client derives its payment endpoints from the trusted QuickPay link origin. The integration guide says to ignore absolute endpoint URLs embedded in the manifest, even if such fields are present. Use HTTPS for that trusted link outside loopback development. A standalone GOAT Flow MPP client can work from a deployment-configured Core origin without the QuickPay manifest, provided you already know the merchant and intended route. Confirm that origin with the deployment that manages the route.

At the end of discovery, the client should know what URL will serve the result, which merchant and route it is paying, and where it is allowed to ask for terms. Its spending policy can now decide whether it is willing to use the route. The current challenge will supply the actual amount and transfer destination.

Read the price from the challenge

In the standalone exchange, the buyer sends JSON to Core at POST /mpp/v1/challenge with Content-Type: application/json. The request names merchant_id, route_canonical, request_canonical, and payer_addr. For this fixed example, both canonical values are GET:api:docs:protected. Use the seller's agreed canonicalization when the requested operation has narrower scope. Paying for a general route does not by itself settle which variants the merchant should deliver.

On this particular POST, HTTP 402 Payment Required is the documented success response. Decode the JSON transfer instruction from it. The body provides challenge_id, expiry, amount_wei, chain_id, token_contract, recipient, mac, and route_pricing_version. amount_wei is the exact amount in the token's smallest units. Preserve it as an integer representation so conversion from a display price cannot round it. Keep the MAC with the challenge to echo back on verify. The client has no need to generate its own MAC.

The client applies its spending policy to the returned terms before involving the signer. Check the merchant and intended route, the pair the buyer is prepared to use, the amount, the recipient expected for that offer, and the remaining time. If the wallet is on a different chain or the price is outside policy, stop before broadcast. Where the expected terms or recipient differ from the challenged values, resolve the discrepancy with the merchant. The fresh challenge defines the transaction fields once the client accepts the offer. Reconstructing them from a manifest, a token symbol, or a cached price risks moving funds that Core cannot match to the challenge.

A fixed decimal amount is convenient for buyers that want a predictable cost for a defined result. This profile binds the pricing version to the challenge and order. If the service needs a quote that changes with the work about to be performed, model that as a separate offer or integration rather than editing fields from a challenge already issued for the snapshot.

Broadcast once and start verification

Send the exact token amount from the payer wallet to the challenge's recipient on the specified chain. Check the deadline and wallet network before broadcast. Once the wallet returns tx_hash, save the challenge and hash along with the payer address. This is enough to reconstruct the verify request, and the wallet's transaction reference can be kept in the client if its supported library uses it to track a fee-bump replacement.

Start verifying as soon as you have the hash. Waiting for a local wallet confirmation before contacting Core can use up the challenge window. The buyer POSTs JSON to Core at /mpp/v1/verify with challenge_id, tx_hash, payer_addr, and the original mac. The verify status controls what the client does even when the wallet reports that the transaction was submitted.


Verify result


Client action

200 with Payment-Receipt

Keep the returned header for the protected request. A missing or malformed value leaves the receipt path incomplete.

202

Core reports pending finality. Respect Retry-After within the client's retry budget and check the same transfer again.

429

Verification is rate limited. Back off according to Retry-After within the retry budget. This status alone says nothing about chain finality.

Terminal 4xx

Stop verify retries. Preserve the transfer context and reconcile any broadcast before authorizing another payment.

5xx

Back off exponentially and retry verification within the configured budget.

The documented buyer adapter bounds both waiting and the number of attempts. Choose retry settings that fit the selected network and the Core deployment's rate limits, and give the caller a way to stop waiting without losing its verification context. A retry loop can stop before the chain has reached the state Core needs. Use the recorded transaction and Core response to determine what happened to the payment. GOAT Flow MPP transfer and verification.

Make pending visible

In a buyer trace, record the time the transaction hash became available, the first verify attempt time, the status from each attempt, and any retry delay. Include the route, chain, challenge identifier and transfer reference in an access-controlled record operators can correlate. Keep the MAC, complete receipt and signer secrets out of routine logs. Persist whatever is needed for resume in storage appropriate to those values. If the agent has its own job runner, keep this record with the job so a restarted worker has a payment to look up.

For a test of an enabled route, observe verification immediately after broadcast and watch for a 202. You may receive 200 first if Core already sees sufficient finality. A wallet indicator or a pending entry on the correct chain's RPC can help you investigate timing, but a pending response from Core is the observation that exercises the buyer's verify branch. If a supported test payment confirms too quickly, use a local fixture returning 202 and Retry-After to check scheduling and state persistence. Keep those fixture results separate from evidence that Core actually returned pending on the test network.

Design recovery around the saved transfer. The documented GOAT Flow adapter surfaces the original challenge, transaction hash and payer address in recoverable post-broadcast errors. Its lower-level verifyChallenge can resume with that context. When an attempt times out after the wallet returned a hash, inspect the transaction on the instructed chain and resume verify on the same challenge where the error and deadline permit it. If the challenge expired, Core rejects it, or the broadcast outcome is unclear, reconcile before offering another payment. Running a full pay operation creates a new challenge and can send funds again.

One practical test is to interrupt the client after it records the hash and before it gets a receipt. On restart, inspect whether it still has enough data to verify the original payment. If the network or Core remains unavailable, the buyer should be able to leave the purchase unresolved for investigation. That is a useful outcome for a failure test because the agent can stop without creating another transfer or representing the snapshot as delivered.

Verify the receipt at the resource

Core returns Payment-Receipt as a response header on successful verification. The buyer sends the value as a Payment-Receipt request header on GET /api/docs/protected at the merchant resource server. The GOAT receipt has three dot-separated segments containing the encoded JSON, the encoded signature and the algorithm identifier. The merchant can use the documented source middleware for Express, Fastify or Go with the receipt verification configuration for its deployment. Check the source integration and its release status before choosing an installation path.

Configure the verifier for the merchant identifier, the canonical route and the trusted Ed25519 public key or HMAC secret matching the deployment. Keep the HMAC secret server-side. The documented checks cover header format, signature, merchant match, route binding and expiry. Route binding can accept an exact canonical match or a suffix under the configured route prefix. For this fixed snapshot, make your application accept the scope you intend to sell. If you later introduce request variants, review how the canonical binding represents them before serving a different object under the same route.

Supply a receipt-ID store if one receipt should be redeemable once. With replicas, make consumption atomic in a shared store so two workers cannot grant separate uses of the same receipt. The documented middleware checks for prior consumption only when a store is configured. Under that policy, a store outage returns 503. Invalid, wrong-merchant or already-consumed receipts receive 401, while a route mismatch or expiry receives 402 on the resource. This 402 has a different purpose from the successful response to the challenge request. Handle it within the resource policy without launching another payment automatically.

The guide documents the transfer identity, merchant, request scope, and expiry in the signed receipt. Core binds the pricing version earlier to the challenge and order, and the current receipt omits that field. A merchant check that needs a pricing-version assertion must get it from a trusted source beyond the receipt fields described here. The handler returns the catalog snapshot only after the checks it relies on have passed.

Check both sides before launch

Use the Merchant Guide's test flow on Testnet3 when the target test merchant has an enabled route and matching receiving pair there. Confirm the public manifest and live challenge before loading the test wallet. Compare the configured identifier and offered terms with the challenge. On the buyer side, record the broadcast and inspect the verify outcome. On the resource side, check that the receipt for the intended merchant and route opens the handler and that an unpaid or out-of-scope request leaves the snapshot protected.

Test rejection on your own resource for missing, malformed, expired and mismatched receipts. If the route uses a consumption store, include repeated use and an unavailable store in the check. Exercise the buyer's lost verify response separately from a lost resource response. The first might be recoverable by checking the original transfer. The second depends on your application's delivery policy after receipt consumption, even when the buyer has paid correctly.

Before exposing the production route, reassess its own manifest and eligibility. A test purchase shows what happened on the test deployment for that configuration. For the production rollout, start with one configured offer and confirm you can tell which component stopped the request if the expected receipt or resource response never arrives. Keep the broadcast reference available until the payment state has been reconciled.

FAQ

Can I change the fixed route price while agents are using it?

Update the route through the supported Portal workflow and check the new public pricing version. Buyers should request fresh terms before authorizing a new transfer. For a transfer already broadcast, follow the original challenge and verify context, and reconcile any expiry before deciding how to handle that payment.

Can an agent call the whole flow from a browser?

Only if the deployment allows its origin. Core needs to permit the JSON POSTs and expose Payment-Receipt for the browser to read. The merchant resource separately needs to allow the browser origin and the Payment-Receipt request header. Use a server-side buyer client when the required Core browser access is unavailable.

Can I reuse my x402 client for this paid route?

Check whether it can perform the GOAT-specific challenge and verify calls, send the instructed direct transfer, and present the signed receipt to the resource. A client that only knows how to retry a protected URL with a standard x402 payment payload needs additional integration for this route.

[01]

AI Knowledge base

More Articles

More Articles

More Articles