Skip to content
Tenzro
← All tutorials
Tutorial · Payments

Pay for inference in stablecoins

Hold USDC in a Bridge.xyz wallet, pay per call for chat, embeddings, audio and vision on Tenzro Network 1 over x402 or MPP, and reconcile every charge.

Beginner15 min

You do not need to hold TNZO to use the network. On Tenzro Network 1 you can keep a stablecoin balance, pay for each inference call in USDC over the open x402 and MPP protocols, and pay gas in stablecoins too. Settlement is metered and per use by default: you pay for what each call actually consumed, and every response tells you what it cost.

This tutorial takes you from an empty wallet to a paid chat completion and a paid transcription, then shows how to reconcile the charges.

Prerequisites

  • A browser and device that support passkeys.
  • Node.js 20 or newer.
  • Background: Stablecoin payments.

1. Create a wallet and add stablecoins

  1. Create a passkey wallet in the console. Link a second device while you are there, so a lost phone never locks you out.
  2. From the wallet page, add a stablecoin wallet. Stablecoin wallets are provided through Bridge.xyz. Deposit USDC to the address it shows.
  3. If you want an agent or a server process to pay rather than your own browser, create a delegated agent in Agents with a daily cap and move an allowance to it. See Build an AI payment agent.

2. See where stablecoin charges can settle

Every charge settles on a rail that can carry it economically. The network publishes the rails it knows, which stablecoins are native on each and whether each speaks x402:

bash
curl -s https://rpc.tenzro.xyz \
  -H 'content-type: application/json' \
  -d '{"jsonrpc":"2.0","id":1,"method":"tenzro_settlementNetworks","params":{}}' \
  | jq '.networks[] | {caip2, name, native_stablecoins, x402, min_payment_micro_usd}'

Pass an amount to see how a specific charge would be routed:

bash
curl -s https://rpc.tenzro.xyz \
  -H 'content-type: application/json' \
  -d '{"jsonrpc":"2.0","id":1,"method":"tenzro_settlementNetworks","params":{"amount_wei":"1000000000000","asset":"USDC"}}' \
  | jq .result.route

settles_now: true means the charge settles on its own. For charges too small to settle alone, the route says so and suggests the remedy: open a payment channel or an MPP session so many small charges settle together.

3. Pay for a chat completion in USDC

Install the AI SDK:

bash
npm install @tenzro/ai

Pass a signer for the paying account and a payment budget in USDC. On each call the SDK receives the provider's 402 Payment Required challenge, pays it over x402 (one-shot) or MPP (streams), and retries.

ts
import { generateText, streamText, tenzro } from "@tenzro/ai";
import { signer } from "./signer"; // your passkey wallet or agent hardware key

const usdc = (units: bigint) => ({ amount: units, currency: "USDC" as const }); // 6 decimals

const { text, receipts } = await generateText({
  model: tenzro("qwen3.6-35b-a3b"),
  prompt: "List three things to check before renting a GPU by the hour.",
  signer,
  payment: { protocol: "x402", maxPrice: usdc(20_000n) }, // at most 0.02 USDC
});

console.log(text);
console.log(receipts.payment);

For long answers, stream and pay per token over one MPP session:

ts
const result = streamText({
  model: tenzro("qwen3.6-35b-a3b"),
  prompt: "Explain how rental escrow works on Tenzro.",
  signer,
  payment: { protocol: "mpp", maxPrice: usdc(100_000n) },
});

console.log(await result.text);
console.log((await result.receipts).payment); // settled when the stream finishes

If the chosen provider quotes above maxPrice, the SDK moves to another provider serving the same model.

4. Pay for other modalities

The same budget works for every paid route: embeddings, images, audio, video and the Tenzro vision and timeseries routes. For example, a transcription:

ts
import { transcribe } from "@tenzro/ai";
import { readFile } from "node:fs/promises";

const out = await transcribe({
  model: "whisper-large-v3-turbo",
  audio: await readFile("meeting.wav"),
  signer,
  payment: { protocol: "x402", maxPrice: usdc(50_000n) },
});
console.log(out);

Without the SDK, call any paid route with curl; the 402 response carries the challenge and the price. See Payments with x402.

5. Reconcile every charge

Each paid response reports what was metered and what it cost. JSON-RPC inference responses also carry a settlement object that says how the call was paid and how the payment was split:

json
{
  "units": { "...": "..." },
  "cost_wei": "…",
  "settlement": {
    "status": "settled",
    "via": "transfer",
    "network_wei": "…",
    "provider_wei": "…",
    "margin_wei": "0",
    "provider": "0x<provider-wallet>",
    "app_id": null
  }
}
  • provider_wei went to the operator who served the call; network_wei to the rest of the network.
  • margin_wei is the developer margin when you call through an app that adds one.
  • via is transfer for a direct payment or channel for a debit from an open payment channel.

Look up any receipt later by id:

bash
curl -s https://rpc.tenzro.xyz \
  -H 'content-type: application/json' \
  -d '{"jsonrpc":"2.0","id":1,"method":"tenzro_getPaymentReceipt","params":[{"receipt_id":"<receipt-id>"}]}'

6. Pay gas in stablecoins too

On-chain actions, such as funding an agent or registering a resource, need gas. Network 1 accepts gas in stablecoins, so a stablecoin-only account can still transact, and apps can sponsor gas for their users with a paymaster. See Build a paymaster app.

Next steps