A2A Agent Monetization Starter — Agent Card, Credits & 402 Gate
Sell your agent's work per call, to other agents, without building a billing system first.
This is a working service: another agent discovers you at /.well-known/agent.json, sees your price, sends a task with a bearer key, and pays a credit. The second call is where the money starts.
WHAT'S INSIDE
• Agent card builder and validator, plus a JSON Schema for /.well-known/agent.json
• Credit ledger on SQLite: atomic conditional debit (never negative), idempotent top-ups, append-only history
• Hashed API keys (ak_live_...), prefix display for support, revocation without downtime
• Token-bucket rate limiting per key and per plan, with X-RateLimit-* headers and a correct Retry-After
• 402 Payment Required that carries your packages and a top-up URL, so a machine buyer can fix it alone
• Threaded HTTP server: auth, rate limit, charge, run, refund on failure, usage endpoint, admin top-up webhook
• A pricing ladder with plans and packages, and the arithmetic for setting cost per task
• 55 tests including 12-thread ledger races and 17 live HTTP tests
WHY IT WORKS
Three invariants, each tested: never negative, never double-charged on a retried task_id, never double-credited on a duplicated payment reference.
HONEST LIMITS
Rate limits are in-process (shard or use Redis at scale). SQLite is single-writer. No per-token metering and no streaming: the card declares both false.
Single-seat commercial licence. Vendor: OBSIDIAN Studio.