Kairo

Examples

1. Monetize an Express API

import express from "express";
import { verifyPaymentProof } from "@kairo/x402";

const app = express();
app.get("/market-analysis", async (req, res) => {
  const headers = { get: (n: string) => (req.header(n) ?? null) };
  if (!(await verifyPaymentProof(process.env.KAIRO_WEBHOOK_SECRET!, headers))) return res.status(401).end();
  res.json({ signal: "…" });
});
// Register https://api.you.com/market-analysis in KAIRO Business → Agent Payments, price 0.05 USDC.

2. Monetize a Next.js route

// app/api/report/route.ts
import { verifyPaymentProof } from "@kairo/x402";
export async function GET(req: Request) {
  if (!(await verifyPaymentProof(process.env.KAIRO_WEBHOOK_SECRET!, req.headers))) return new Response(null, { status: 401 });
  return Response.json({ report: "…" });
}

3. x402 agent client

const client = new KairoX402Client({ account, maxPaymentUnits: 2_000_000n });
const res = await client.fetch(PAYMENT_URL);

4–5. Create an agent wallet and set limits

// In the app: /agents/create — name, limits (e.g. $2 per payment, $25/day), approved merchants/domains, expiry.
// Limits are enforced by KAIRO (atomic database budget) before Circle signs; Circle wallet limits apply on top.

6. Process a paid request (raw HTTP)

GET  /api/public/x402/r/<id>                      → 402 + PAYMENT-REQUIRED
GET  /api/public/x402/r/<id>  PAYMENT-SIGNATURE: …  → 200 + PAYMENT-RESPONSE (after Circle settle + Arc receipt)

7. Receive webhooks

app.post("/kairo-webhook", express.raw({ type: "*/*" }), async (req, res) => {
  const ok = await verifyWebhook(process.env.KAIRO_WEBHOOK_SECRET!, req.body.toString(), req.header("KAIRO-Signature") ?? null);
  if (!ok) return res.status(400).end();
  const evt = JSON.parse(req.body.toString()); // { event: "payment.settled", data: { id, gross, fee, net, transaction, … } }
  // de-duplicate on KAIRO-Event-Id
  res.sendStatus(200);
});

8. KLIK agent checkout

const co = await getCheckout("https://kairo.market/api/public/klik/agent/<id>");
// show co.product, co.price, co.refundPolicy to the owner / check policy, then:
const order = await payCheckout(client, co, { email: "buyer@example.com" });

9. Swap quote

const api = new KairoAgentApi({ apiKey: process.env.KAIRO_API_KEY! });
const q = await api.swapQuote({ agentId, tokenIn: USDC, tokenOut: TOKEN, amountIn: "1000000", slippageBps: 50 });
if (q.decision !== "allow") throw new Error(q.reason ?? "denied");

10. Authorized swap execution

// Status: not enabled. Agent swaps will be signed only by the agent's Circle wallet after the quote's
// policy decision is "allow". Until the Circle runner swap operation is enabled, execution returns
// { execution: { status: "not_enabled" } } and nothing is broadcast.