Quickstart

Get a payment-protected API endpoint running in under 5 minutes.

1. Install the SDK

npm install @zeny/sdk

2. Create a Payment-Protected API

// app/api/premium/route.ts
import { createZenyMiddleware } from "@zeny/sdk/server";

const zeny = createZenyMiddleware({
  apiKey: process.env.ZENY_API_KEY!,
  payTo: "0xYourWalletAddress",
  amount: "0.01", // 0.01 USDM per request
});

export async function GET(req: Request) {
  // Check for payment
  const paymentResponse = await zeny(req);
  if (paymentResponse) return paymentResponse;

  // Payment verified — serve premium content
  return Response.json({
    data: "This is premium AI-powered content",
    timestamp: new Date().toISOString(),
  });
}

3. Test the Flow

# First request — gets 402
curl -i http://localhost:3000/api/premium
# HTTP/1.1 402 Payment Required
# Payment-Required: base64(...)

# Agent retries with payment signature
curl -i http://localhost:3000/api/premium \
  -H "Payment-Signature: base64(signed_payload)"
# HTTP/1.1 200 OK
# { "data": "This is premium AI-powered content" }

4. Monitor in Dashboard

All settlements appear in real-time on your Seller Dashboard. Each transaction links to the MegaETH block explorer for on-chain verification.

What's Next?