Monetization

RaaS Onboarding

Repository-as-a-Service. Wrap any CLI or API with license gating, MCU metering, and Polar.sh billing in under an hour.

Overview

RaaS (Repository as a Service) is OpenClaw's monetization layer. It provides:

  • License gate — HTTP 402 on zero balance, JWT verification
  • MCU metering — per-request credit deduction with rollback on failure
  • Polar.sh webhooks — automatic credit top-up on subscription payment
  • Audit trail — full transaction log per tenant
  • KV cache — Cloudflare KV for fast balance lookups

The RaaS gateway runs as a Cloudflare Worker. Deploy time: ~2 minutes.

Register Tenant

Initialize your RaaS tenant from the CLI:

mekong raas/init --name "My Product" --email you@company.com

This scaffolds the gateway worker, registers you in the tenant registry, and outputs your tenant ID:

Tenant registered: tenant_abc123
Gateway URL: https://gateway.myproduct.workers.dev
Admin dashboard: https://raas.openclaw.ai/tenant/tenant_abc123

API Keys

Generate your first API key:

mekong raas/key/create --name "production" --tier pro

List all keys:

mekong raas/key/list

Rotate a key:

mekong raas/key/rotate --id key_xyz789

Protect your gateway by validating the key in each request header:

Authorization: Bearer <YOUR_API_KEY>
warning

Never commit API keys to git. Store in .env or Cloudflare Secrets.

Credit Management

Check balance for a tenant:

mekong raas/balance --tenant tenant_abc123

Manually top up credits (e.g. for testing):

mekong raas/topup --tenant tenant_abc123 --amount 100

View transaction history:

mekong raas/ledger --tenant tenant_abc123 --last 50

Set MCU cost per endpoint in your worker config:

{
  "routes": {
    "POST /v1/missions": { "mcu": 2 },
    "POST /v1/cook": { "mcu": 1 },
    "GET /v1/status": { "mcu": 0 }
  }
}

Polar Webhook Setup

Connect Polar.sh to automatically credit users on payment:

  1. Go to your Polar.sh dashboard
  2. Navigate to Settings → Webhooks → Add Endpoint
  3. Enter your gateway URL: https://gateway.myproduct.workers.dev/webhooks/polar
  4. Select events: subscription.created, subscription.renewed, order.paid
  5. Copy the webhook secret and set it in your worker:
wrangler secret put POLAR_WEBHOOK_SECRET

The gateway automatically maps Polar product IDs to MCU tiers defined in your config.