Castor docs
Castor is buyer protection for AI agents paying over x402 on Solana. Sellers lock a USDC bond. When a paid call leaks (times out, errors, breaks its schema or comes back empty) the agent is refunded from that bond in seconds. Sellers are still paid instantly.
How it works
Castor never holds the agent's payment. The seller's bond is the guarantee, so small calls stay as fast as plain x402.
- 1Seller builds the dam. The seller deposits USDC into a bond account and registers its endpoints with their price, checks and output schema.
- 2Agent pays through a watcher. The agent sends a normal x402 request. A Castor watcher forwards it, settles the payment straight to the seller and receives the response.
- 3Checks run, leaks get refunded. The watcher runs the endpoint's leak checks. Clean responses go to the agent. A failed check produces a signed leak report, and the program refunds the agent from the seller's bond.
Quickstart: sellers
1. Install the middleware.
npm install @castor/seller
2. Protect an endpoint. Wrap any x402 route. Declare a price, the checks you accept and, for schema, the JSON Schema of your response.
import { castor } from "@castor/seller"; import weatherSchema from "./weather.schema.json"; app.use("/api/weather", castor.protect({ price: "0.01 USDC", checks: ["timeout:3s", "status", "schema", "empty"], schema: weatherSchema, }));
3. Build the dam. Connect Phantom in the Castor app, open Seller dashboard → Bond and deposit USDC. Your endpoints get the Castor badge as soon as the bond covers the minimum.
Quickstart: agents
npm install @castor/agent
import { withCastor } from "@castor/agent"; const pay = withCastor(x402Client, { onlyProtected: true, onRefund: (r) => console.log("refunded", r.amount, r.reason), }); const res = await pay.fetch("https://api.example.com/weather");
With onlyProtected on, the client refuses to pay endpoints without a live Castor bond. Refunds land in the paying wallet; no claim step.
Leak checks
Only checks a machine can prove. Sellers choose which ones apply to each endpoint; agents see them in the catalog before paying.
| Check | Config | Fires when |
|---|---|---|
| timeout | timeout:3s | No complete response inside the declared window |
| status | status | Any 4xx or 5xx after the payment settled |
| schema | schema + JSON Schema | The body fails validation against the published schema |
| empty | empty | 200 OK with an empty body, null or an empty object/array |
Bonds & coverage
- Bonds are USDC. Protection never depends on a token price.
- Coverage is capped by the bond. A refund can never exceed what is left in the seller's bond. Agents see live coverage per endpoint in the catalog.
- Minimum bond. Below the minimum [VALUE TBD] the badge is removed until the seller tops up.
- Withdrawals have a cooldown. Sellers request a withdrawal and wait [PERIOD TBD], so the dam can't be drained right before a run of leaks.
- Backstop. From Phase 04, the $CSTR backstop pool covers refunds a dry bond can't.
Watchers
A watcher is an x402 facilitator that sits in the payment path. Because it sees both the payment and the response first-hand, a refund is triggered by what actually happened, not by what the agent claims.
- Phase 01: Castor runs the watcher and signs leak reports.
- Phase 02: anyone can run a watcher by staking $CSTR. A leak report needs a quorum of watcher signatures; signing a false report is slashed.
Beaver Score
Every protected endpoint gets a public score in the catalog. Agents use it to choose who to pay; sellers use it to climb the rankings.
Seller SDK
castor.protect(options)
| Option | Type | Description |
|---|---|---|
| price | string | Price per call in USDC, e.g. "0.01 USDC" |
| checks | string[] | Leak checks for this endpoint |
| schema | JSONSchema | Output schema; required with the schema check |
| bond | PublicKey? | Bond account to cover this endpoint; defaults to the seller's main bond |
Agent SDK
withCastor(x402Client, options)
| Option | Type | Description |
|---|---|---|
| onlyProtected | boolean | Refuse to pay endpoints without a live bond |
| minScore | number? | Skip endpoints below this Beaver Score |
| maxPrice | string? | Never pay more than this per call |
| onRefund | (refund) => void | Called with amount, reason and transaction when a refund lands |
On-chain program
An Anchor program on Solana. Program ID: [coming soon]
SellerBondUSDC vault, coverage, withdrawal requestEndpointURL hash, price, checks, schema hashLeakReportpayment tx, failed check, watcher signatures
init_bond·depositrequest_withdraw·withdrawregister_endpointsubmit_leak_report→ refund
$CSTR
Every beaver has a job. Contract address: [coming soon]
| Role | What you do | What you get |
|---|---|---|
| Watcher | Stake, run a node, co-sign leak reports | Fees; slashed for false reports |
| Arbiter | Stake, judge disputes on big payments | Fees; slashed against the honest majority |
| Second dam | Stake in the backstop pool | Cut of protection fees; covers dry bonds |
| Voucher | Delegate to sellers you trust | Share of their fees; bitten if they leak |
| Seller | Hold or stake | Lower fees, catalog boost, faster badge |
| Agent | Stake | Higher coverage per call, premium checks |
| Holder | Vote | Govern checks, fees, bonds; buybacks from fees |
FAQ
No. Refunds follow what watchers observed, never what the agent claims.
No. Payments settle to the seller instantly; the bond is the guarantee.
From Phase 03, payments above a threshold use escrow with a challenge window and staked arbiters.