Meter LLM inference on a tab
Your agent calls the inference endpoint and pays a flat rate per completion. The tab caps total spend across all calls, so a runaway loop or a bad prompt can't drain your wallet.
Charge a flat rate per completion call. Each call meters into the tab and reserves what's accrued on-chain — you're paid for exactly what you served, and the buyer's cumulative bill is capped.
Seller: charge per completion call
Protect your inference route with tabOrExactMiddleware. Set a flat perUnit price in USDC per call — price each call as a token-bucket (e.g. one call = one 512-token completion). The middleware handles the 402 handshake; your route only runs after payment settles. The buyer's tab caps cumulative spend across all calls, so the total bill is bounded before the first request is made.
import express from 'express';
import { Connection } from '@solana/web3.js';
import { tabOrExactMiddleware } from '@dexterai/x402/tab/seller';
const app = express();
const connection = new Connection(process.env.SOLANA_RPC_URL!);
// Each completion call costs perUnit USDC. The buyer's tab caps cumulative spend
// across all calls and reserves what's accrued on-chain — they can't be over-billed,
// you can't be drained.
app.post('/v1/chat',
tabOrExactMiddleware({
connection,
sellerPubkey: process.env.SELLER_SOLANA_ADDRESS!,
network: 'solana:mainnet',
perUnit: '0.002', // USDC per completion call
}),
async (req, res) => {
const completion = await runInference(req.body);
res.json(completion);
},
);Buyer: spend within the tab
Call the seller's endpoint with payAndFetch. The client handles the 402 response, signs with your Solana keypair, and retries — all in one call. If the tab cap is reached, the call fails rather than draining past your limit.
import { payAndFetch, createKeypairWallet } from '@dexterai/x402/client';
const solana = await createKeypairWallet(process.env.AGENT_KEY!);
const result = await payAndFetch('https://seller.example/v1/chat', {
method: 'POST',
body: JSON.stringify({ messages, max_tokens: 512 }),
}, { solana });
if (result.ok) console.log(await result.response.json());Funding the tab (cross-property handoff)
The buyer opens and funds a tab via the hosted passkey flow — no private-key custody required. Once funded, the spending authorization is passed to the agent, which calls the seller API directly. The tab enforces the cap on-chain; the seller meters per call.
- Open a tab at dexter.cash/tabs — set a USDC cap and expiry. Money stays in your wallet until metered.
- Receive a spending authorization (signed on-chain). Hand it to your agent.
- The agent calls the seller's API with
payAndFetch. Each completion call meters into the tab and reserves on-chain. - On close or expiry, the seller settles the reserved amount. Drain-proof both ways.