EXAMPLE · GPU RENTAL

Rent GPU compute on a tab

Buyer

Rent compute by the metered call without a blank check. The tab caps cumulative spend across calls, so a job that overshoots stops at your limit instead of your balance.

Seller

Charge a flat rate per lease tick. The tab reserves what's accrued on-chain — you're paid for exactly the calls you served.

Seller: charge per lease tick

Protect your compute lease route with tabOrExactMiddleware. Set a flat perUnit price in USDC per call — price each call as a metered tick (e.g. one call = one job dispatch or one time-slice). The buyer's tab caps cumulative spend across all ticks; you can't be stiffed after serving.

typescript
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 lease tick costs perUnit USDC. The buyer's tab caps cumulative spend
// across all calls and reserves what's accrued on-chain — you're paid for what
// you served, they can't be billed past their cap.
app.post('/lease',
  tabOrExactMiddleware({
    connection,
    sellerPubkey: process.env.SELLER_SOLANA_ADDRESS!,
    network: 'solana:mainnet',
    perUnit: '0.05', // USDC per lease tick / metered call
  }),
  async (req, res) => {
    const jobResult = await runJob(req.body);
    res.json(jobResult);
  },
);

Buyer: rent within the cap

Call the compute endpoint with payAndFetch. Specify the job parameters and duration. If the accrued cost would exceed the tab cap, the reservation fails cleanly — your wallet is never exposed beyond the limit you set.

typescript
import { payAndFetch, createKeypairWallet } from '@dexterai/x402/client';

const solana = await createKeypairWallet(process.env.AGENT_KEY!);
const result = await payAndFetch('https://compute.example/lease', {
  method: 'POST',
  body: JSON.stringify({ model: 'sdxl', steps: 40, duration_secs: 60 }),
}, { solana });
if (result.ok) console.log(await result.response.json());

Why tabs fit long-running compute

GPU jobs are the canonical tab use case. A single job can dispatch many metered calls, with each tick accruing cost. Without a cap, a misconfig or a hung job can drain a wallet. With a tab, the on-chain cap is enforced before any reservation is made — the job stops at your limit, not at zero balance. The seller is paid for exactly what they served, and the buyer keeps the rest.

Open a tab at dexter.cash/tabs, set a USDC cap for the compute run, and hand the spending authorization to your job scheduler. Each lease tick meters into the tab and reserves on-chain.