@valiron/sdk 2.0.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,146 @@
1
+ /**
2
+ * Application-owned wallet proof verification for the Cloudflare trust gate.
3
+ *
4
+ * This is the edge (workerd-safe) verify side of the `valiron-wallet-request-v2`
5
+ * signed-request contract documented in docs/SECURITY-UPGRADE-2026-10-31.md and
6
+ * implemented server-side in services/edge-proxy requestProof.ts. It lets an API
7
+ * seller verify an ordinary (non-ANS) agent's ownership proof locally in a
8
+ * Cloudflare Worker, bound to the agent's current registry owner wallet from the
9
+ * live Valiron profile.
10
+ *
11
+ * Contract mirrored exactly:
12
+ * - headers: x-agent-timestamp (13-digit ms), x-agent-nonce (24-128 URL-safe
13
+ * chars), x-agent-request-signature
14
+ * - payload lines joined with "\n":
15
+ * valiron-wallet-request-v2
16
+ * agent:<exact-request-agent-id>
17
+ * chain:<network string, as resolved for the agent>
18
+ * method:<UPPERCASE method>
19
+ * url:<absolute public request URL (request.url verbatim)>
20
+ * body-sha256:<lowercase hex sha256 of ("" for no body, else
21
+ * JSON.stringify(JSON.parse(rawBody)))>
22
+ * timestamp:<ms>
23
+ * nonce:<fresh nonce>
24
+ * - timestamp window: |now - timestamp| <= 60_000 ms
25
+ * - nonce consumed exactly once per wallet+network+nonce scope
26
+ * (sha256 hex of `<wallet|wallet.toLowerCase()>:<network>:<nonce>`), TTL 121s
27
+ * - EVM: EIP-191 personal_sign over the UTF-8 payload, recovered address must
28
+ * equal the registry owner wallet (case-insensitive)
29
+ * - Solana: Ed25519 over the UTF-8 payload, signature base64url, wallet is the
30
+ * base58 public key
31
+ *
32
+ * Replay protection is MANDATORY: pass a durable `nonceStore`. In Cloudflare
33
+ * Workers use a Durable Object (see examples/cloudflare-gate-worker). Without a
34
+ * store this module fails closed.
35
+ */
36
+ /** Durable, atomic nonce claimer. Implementations must be atomic across all
37
+ * isolates that serve the gate (a Durable Object or equivalent shared store). */
38
+ export interface NonceStore {
39
+ /** Returns true exactly once per `scope` within `ttlSeconds`; false on replay
40
+ * or when the store is unavailable (callers fail closed). */
41
+ claim(scope: string, ttlSeconds: number): Promise<boolean>;
42
+ }
43
+ /**
44
+ * TEST/LOCAL ONLY. Atomic within a single isolate; NOT safe as a production
45
+ * replay control across Cloudflare isolates or restarts. The deployable
46
+ * template binds a Durable Object instead.
47
+ */
48
+ export declare class MemoryNonceStore implements NonceStore {
49
+ private seen;
50
+ claim(scope: string, ttlSeconds: number): Promise<boolean>;
51
+ }
52
+ /** Chain-specific cryptographic primitives, supplied by the integrating app so
53
+ * the SDK stays dependency-free. The Cloudflare template ships ready-made
54
+ * adapters (viem for EVM, WebCrypto Ed25519 for Solana). */
55
+ export interface WalletProofCrypto {
56
+ /** EIP-191: recover the signer address of `message` (UTF-8) from a 0x-hex
57
+ * signature. Return lowercase hex. */
58
+ recoverEvmAddress(message: string, signature: string): Promise<string>;
59
+ /** Ed25519: verify a base64url signature over the UTF-8 `message` against the
60
+ * base58 Solana public key. */
61
+ verifySolanaSignature(message: string, signatureBase64url: string, publicKeyBase58: string): Promise<boolean>;
62
+ }
63
+ export interface WalletProofVerificationConfig {
64
+ /** Exact agent id as the request claims it (gate-resolved identifier). */
65
+ agentId: string;
66
+ /** Network/chain string the proof signs over - the same string the gate used
67
+ * to resolve the agent (e.g. the profile's chain.network value). */
68
+ network: string;
69
+ /** Current registry owner wallet from the live profile (EVM 0x address, or
70
+ * base58 Solana public key). For key-based agents: the agent's own address. */
71
+ registryWallet: string;
72
+ /** True when `network` is a Solana network (wallet is base58, Ed25519). */
73
+ isSolana: boolean;
74
+ /** Durable nonce store. REQUIRED - verification fails closed without it. */
75
+ nonceStore: NonceStore;
76
+ crypto: WalletProofCrypto;
77
+ /** Timestamp tolerance in ms (default 60_000, matching the server). */
78
+ maxAgeMs?: number;
79
+ /** Injectable clock for tests. */
80
+ now?: number;
81
+ }
82
+ export type WalletProofResult = {
83
+ ok: true;
84
+ } | {
85
+ ok: false;
86
+ reason: string;
87
+ };
88
+ declare function base64urlToBytes(value: string): Uint8Array;
89
+ /** Build the exact canonical payload the agent signed. Exported for tests and
90
+ * for the sign-side recipe; the layout must stay byte-identical with the
91
+ * server implementation. */
92
+ export declare function buildWalletProofPayload(input: {
93
+ agentId: string;
94
+ network: string;
95
+ method: string;
96
+ url: string;
97
+ bodySha256: string;
98
+ timestamp: string;
99
+ nonce: string;
100
+ }): string;
101
+ /**
102
+ * Verify one inbound request's wallet proof headers against the live registry
103
+ * owner. `rawBody` is the exact request body text ("" when none); JSON bodies
104
+ * are canonicalized exactly as the server does (parse then stringify), and a
105
+ * body that fails to parse can never produce a valid proof.
106
+ */
107
+ export declare function verifyWalletRequestProof(request: {
108
+ method: string;
109
+ url: string;
110
+ headers: {
111
+ get(name: string): string | null;
112
+ };
113
+ }, rawBody: string, config: WalletProofVerificationConfig): Promise<WalletProofResult>;
114
+ /** Decode a base58 Solana public key to its 32 raw bytes. Shipped so templates
115
+ * need no dependency for the Ed25519 path. Throws on invalid input. */
116
+ export declare function base58Decode(value: string): Uint8Array;
117
+ /** WebCrypto Ed25519 adapter for Solana wallets - ready to use in Workers.
118
+ * Builds the SPKI wrapper around the raw 32-byte key exactly like the server's
119
+ * Node verifier does. */
120
+ export declare const webCryptoSolanaVerifier: WalletProofCrypto["verifySolanaSignature"];
121
+ /** base64urlToBytes exported for adapters/tests. */
122
+ export { base64urlToBytes };
123
+ /** Owner resolution for one gate identifier: the current registry owner wallet
124
+ * plus the network string the proof signs over, from the LIVE Valiron profile.
125
+ * Return null when the identifier is unknown (verification fails closed). */
126
+ export type WalletProofOwnerResolver = (identifier: string) => Promise<{
127
+ wallet: string;
128
+ network: string;
129
+ isSolana: boolean;
130
+ } | null>;
131
+ /**
132
+ * Ready-to-use `verifyRequest` for `runValironEdgeGate`: verifies the
133
+ * application-owned wallet proof (x-agent-timestamp / x-agent-nonce /
134
+ * x-agent-request-signature) of every identified request against the live
135
+ * registry owner, with mandatory durable replay protection.
136
+ *
137
+ * This is the default verifier for ordinary non-ANS agents. Valiron's hosted
138
+ * ANS provider-identity verification remains available via
139
+ * createEdgeIdentityVerifier for ans:// identities.
140
+ */
141
+ export declare function createEdgeWalletProofVerifier(config: {
142
+ resolveOwner: WalletProofOwnerResolver;
143
+ nonceStore: NonceStore;
144
+ crypto: WalletProofCrypto;
145
+ maxAgeMs?: number;
146
+ }): (request: Request, identifier: string) => Promise<boolean>;
@@ -0,0 +1,243 @@
1
+ "use strict";
2
+ /**
3
+ * Application-owned wallet proof verification for the Cloudflare trust gate.
4
+ *
5
+ * This is the edge (workerd-safe) verify side of the `valiron-wallet-request-v2`
6
+ * signed-request contract documented in docs/SECURITY-UPGRADE-2026-10-31.md and
7
+ * implemented server-side in services/edge-proxy requestProof.ts. It lets an API
8
+ * seller verify an ordinary (non-ANS) agent's ownership proof locally in a
9
+ * Cloudflare Worker, bound to the agent's current registry owner wallet from the
10
+ * live Valiron profile.
11
+ *
12
+ * Contract mirrored exactly:
13
+ * - headers: x-agent-timestamp (13-digit ms), x-agent-nonce (24-128 URL-safe
14
+ * chars), x-agent-request-signature
15
+ * - payload lines joined with "\n":
16
+ * valiron-wallet-request-v2
17
+ * agent:<exact-request-agent-id>
18
+ * chain:<network string, as resolved for the agent>
19
+ * method:<UPPERCASE method>
20
+ * url:<absolute public request URL (request.url verbatim)>
21
+ * body-sha256:<lowercase hex sha256 of ("" for no body, else
22
+ * JSON.stringify(JSON.parse(rawBody)))>
23
+ * timestamp:<ms>
24
+ * nonce:<fresh nonce>
25
+ * - timestamp window: |now - timestamp| <= 60_000 ms
26
+ * - nonce consumed exactly once per wallet+network+nonce scope
27
+ * (sha256 hex of `<wallet|wallet.toLowerCase()>:<network>:<nonce>`), TTL 121s
28
+ * - EVM: EIP-191 personal_sign over the UTF-8 payload, recovered address must
29
+ * equal the registry owner wallet (case-insensitive)
30
+ * - Solana: Ed25519 over the UTF-8 payload, signature base64url, wallet is the
31
+ * base58 public key
32
+ *
33
+ * Replay protection is MANDATORY: pass a durable `nonceStore`. In Cloudflare
34
+ * Workers use a Durable Object (see examples/cloudflare-gate-worker). Without a
35
+ * store this module fails closed.
36
+ */
37
+ Object.defineProperty(exports, "__esModule", { value: true });
38
+ exports.webCryptoSolanaVerifier = exports.MemoryNonceStore = void 0;
39
+ exports.buildWalletProofPayload = buildWalletProofPayload;
40
+ exports.verifyWalletRequestProof = verifyWalletRequestProof;
41
+ exports.base58Decode = base58Decode;
42
+ exports.base64urlToBytes = base64urlToBytes;
43
+ exports.createEdgeWalletProofVerifier = createEdgeWalletProofVerifier;
44
+ /**
45
+ * TEST/LOCAL ONLY. Atomic within a single isolate; NOT safe as a production
46
+ * replay control across Cloudflare isolates or restarts. The deployable
47
+ * template binds a Durable Object instead.
48
+ */
49
+ class MemoryNonceStore {
50
+ constructor() {
51
+ this.seen = new Map();
52
+ }
53
+ async claim(scope, ttlSeconds) {
54
+ const now = Date.now();
55
+ for (const [k, exp] of this.seen)
56
+ if (exp <= now)
57
+ this.seen.delete(k);
58
+ if (this.seen.has(scope))
59
+ return false;
60
+ this.seen.set(scope, now + ttlSeconds * 1000);
61
+ return true;
62
+ }
63
+ }
64
+ exports.MemoryNonceStore = MemoryNonceStore;
65
+ const encoder = new TextEncoder();
66
+ async function sha256Hex(input) {
67
+ const digest = await crypto.subtle.digest("SHA-256", encoder.encode(input));
68
+ return [...new Uint8Array(digest)].map((b) => b.toString(16).padStart(2, "0")).join("");
69
+ }
70
+ function base64urlToBytes(value) {
71
+ const b64 = value.replace(/-/g, "+").replace(/_/g, "/");
72
+ const bin = atob(b64 + "=".repeat((4 - (b64.length % 4)) % 4));
73
+ const out = new Uint8Array(bin.length);
74
+ for (let i = 0; i < bin.length; i++)
75
+ out[i] = bin.charCodeAt(i);
76
+ return out;
77
+ }
78
+ /** Build the exact canonical payload the agent signed. Exported for tests and
79
+ * for the sign-side recipe; the layout must stay byte-identical with the
80
+ * server implementation. */
81
+ function buildWalletProofPayload(input) {
82
+ return [
83
+ "valiron-wallet-request-v2",
84
+ `agent:${input.agentId}`,
85
+ `chain:${input.network}`,
86
+ `method:${input.method.toUpperCase()}`,
87
+ `url:${input.url}`,
88
+ `body-sha256:${input.bodySha256.toLowerCase()}`,
89
+ `timestamp:${input.timestamp}`,
90
+ `nonce:${input.nonce}`,
91
+ ].join("\n");
92
+ }
93
+ /**
94
+ * Verify one inbound request's wallet proof headers against the live registry
95
+ * owner. `rawBody` is the exact request body text ("" when none); JSON bodies
96
+ * are canonicalized exactly as the server does (parse then stringify), and a
97
+ * body that fails to parse can never produce a valid proof.
98
+ */
99
+ async function verifyWalletRequestProof(request, rawBody, config) {
100
+ const timestamp = request.headers.get("x-agent-timestamp") ?? "";
101
+ const nonce = request.headers.get("x-agent-nonce") ?? "";
102
+ const signature = request.headers.get("x-agent-request-signature") ?? "";
103
+ const now = config.now ?? Date.now();
104
+ const maxAge = config.maxAgeMs ?? 60000;
105
+ // Custom windows may tighten freshness, never extend it beyond the durable
106
+ // store's retention horizon. Include the future-skew boundary in retention.
107
+ if (!Number.isFinite(maxAge) || maxAge <= 0 || maxAge > 60000)
108
+ return { ok: false, reason: "invalid_timestamp_window" };
109
+ if (!/^\d{13}$/.test(timestamp) || Math.abs(now - Number(timestamp)) > maxAge) {
110
+ return { ok: false, reason: "stale_or_invalid_timestamp" };
111
+ }
112
+ if (!/^[A-Za-z0-9_-]{24,128}$/.test(nonce) || !signature) {
113
+ return { ok: false, reason: "missing_or_invalid_proof_headers" };
114
+ }
115
+ // Canonical body digest: empty string for no body, otherwise
116
+ // JSON.stringify of the parsed JSON body (mirrors the server exactly).
117
+ let bodyForDigest = "";
118
+ if (rawBody !== "") {
119
+ try {
120
+ bodyForDigest = JSON.stringify(JSON.parse(rawBody));
121
+ }
122
+ catch {
123
+ return { ok: false, reason: "body_not_canonical_json" };
124
+ }
125
+ }
126
+ const bodySha256 = await sha256Hex(bodyForDigest);
127
+ const payload = buildWalletProofPayload({
128
+ agentId: config.agentId,
129
+ network: config.network,
130
+ method: request.method,
131
+ url: request.url,
132
+ bodySha256,
133
+ timestamp,
134
+ nonce,
135
+ });
136
+ let valid = false;
137
+ try {
138
+ if (config.isSolana) {
139
+ valid = await config.crypto.verifySolanaSignature(payload, signature, config.registryWallet);
140
+ }
141
+ else {
142
+ const recovered = await config.crypto.recoverEvmAddress(payload, signature);
143
+ valid = recovered.toLowerCase() === config.registryWallet.toLowerCase();
144
+ }
145
+ }
146
+ catch {
147
+ return { ok: false, reason: "signature_verification_error" };
148
+ }
149
+ if (!valid)
150
+ return { ok: false, reason: "ownership_proof_invalid" };
151
+ const scopeWallet = config.isSolana ? config.registryWallet : config.registryWallet.toLowerCase();
152
+ const scope = await sha256Hex(`${scopeWallet}:${config.network}:${nonce}`);
153
+ if (!config.nonceStore)
154
+ return { ok: false, reason: "replay_store_unavailable" };
155
+ let claimed = false;
156
+ try {
157
+ claimed = await config.nonceStore.claim(scope, 121);
158
+ }
159
+ catch {
160
+ claimed = false;
161
+ }
162
+ if (!claimed)
163
+ return { ok: false, reason: "proof_replay_or_store_unavailable" };
164
+ return { ok: true };
165
+ }
166
+ /** Decode a base58 Solana public key to its 32 raw bytes. Shipped so templates
167
+ * need no dependency for the Ed25519 path. Throws on invalid input. */
168
+ function base58Decode(value) {
169
+ const ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
170
+ let num = 0n;
171
+ for (const ch of value) {
172
+ const idx = ALPHABET.indexOf(ch);
173
+ if (idx < 0)
174
+ throw new Error("invalid base58");
175
+ num = num * 58n + BigInt(idx);
176
+ }
177
+ let hex = num.toString(16);
178
+ if (hex.length % 2)
179
+ hex = "0" + hex;
180
+ const bytes = new Uint8Array(hex.length / 2);
181
+ for (let i = 0; i < bytes.length; i++)
182
+ bytes[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16);
183
+ // Restore leading zero bytes (base58 '1's).
184
+ let leading = 0;
185
+ for (const ch of value) {
186
+ if (ch === "1")
187
+ leading++;
188
+ else
189
+ break;
190
+ }
191
+ const out = new Uint8Array(leading + bytes.length);
192
+ out.set(bytes, leading);
193
+ return out;
194
+ }
195
+ /** WebCrypto Ed25519 adapter for Solana wallets - ready to use in Workers.
196
+ * Builds the SPKI wrapper around the raw 32-byte key exactly like the server's
197
+ * Node verifier does. */
198
+ const webCryptoSolanaVerifier = async (message, signatureBase64url, publicKeyBase58) => {
199
+ const SPKI_ED25519_PREFIX = base64urlToBytes("MCowBQYDK2VwAyEA"); // 302a300506032b6570032100
200
+ const rawKey = base58Decode(publicKeyBase58);
201
+ if (rawKey.length !== 32)
202
+ return false;
203
+ const spki = new Uint8Array(SPKI_ED25519_PREFIX.length + 32);
204
+ spki.set(SPKI_ED25519_PREFIX, 0);
205
+ spki.set(rawKey, SPKI_ED25519_PREFIX.length);
206
+ const key = await crypto.subtle.importKey("spki", spki, { name: "Ed25519" }, false, ["verify"]);
207
+ return crypto.subtle.verify("Ed25519", key, base64urlToBytes(signatureBase64url), encoder.encode(message));
208
+ };
209
+ exports.webCryptoSolanaVerifier = webCryptoSolanaVerifier;
210
+ /**
211
+ * Ready-to-use `verifyRequest` for `runValironEdgeGate`: verifies the
212
+ * application-owned wallet proof (x-agent-timestamp / x-agent-nonce /
213
+ * x-agent-request-signature) of every identified request against the live
214
+ * registry owner, with mandatory durable replay protection.
215
+ *
216
+ * This is the default verifier for ordinary non-ANS agents. Valiron's hosted
217
+ * ANS provider-identity verification remains available via
218
+ * createEdgeIdentityVerifier for ans:// identities.
219
+ */
220
+ function createEdgeWalletProofVerifier(config) {
221
+ return async (request, identifier) => {
222
+ let owner;
223
+ try {
224
+ owner = await config.resolveOwner(identifier);
225
+ }
226
+ catch {
227
+ return false;
228
+ }
229
+ if (!owner || !owner.wallet || !owner.network)
230
+ return false;
231
+ const rawBody = await request.clone().text();
232
+ const result = await verifyWalletRequestProof(request, rawBody, {
233
+ agentId: identifier,
234
+ network: owner.network,
235
+ registryWallet: owner.wallet,
236
+ isSolana: owner.isSolana,
237
+ nonceStore: config.nonceStore,
238
+ crypto: config.crypto,
239
+ ...(config.maxAgeMs !== undefined ? { maxAgeMs: config.maxAgeMs } : {}),
240
+ });
241
+ return result.ok;
242
+ };
243
+ }
@@ -272,6 +272,8 @@ export interface ValironGateCheckResult {
272
272
  * ```
273
273
  */
274
274
  export declare function valironGateCheck(sdk: ValironSDK, opts: {
275
+ /** Retain automatic evaluation work after an edge response. */
276
+ waitUntil?: (pending: Promise<unknown>) => void;
275
277
  /** On-chain agent ID (ERC-8004 / Solana). */
276
278
  agentId?: string | null;
277
279
  /** Key-based agent hash (web2). Checked if agentId is not provided. */
@@ -71,7 +71,8 @@ function keyProfileToGateResult(profile, minScore) {
71
71
  const tier = (profile.tier ?? "C");
72
72
  const riskLevel = (profile.riskLevel ?? "RED");
73
73
  const route = (profile.route ?? "sandbox_only");
74
- const allow = profile.verified && score >= minScore;
74
+ const isProductionRoute = route === "prod" || route === "prod_throttled";
75
+ const allow = profile.verified && isProductionRoute && score >= minScore;
75
76
  return {
76
77
  allow,
77
78
  score,
@@ -813,7 +814,8 @@ async function valironGateCheck(sdk, opts) {
813
814
  result = profileToGateResult(profile, effectiveMinScore);
814
815
  // Detect brand-new agent: on-chain identity exists but zero reputation.
815
816
  if (!result.allow && (profile.onchainReputation?.totalFeedback ?? 0) === 0) {
816
- sdk.triggerSandboxTest(agentId).catch(() => { });
817
+ const pending = sdk.triggerSandboxTest(agentId).catch(() => { });
818
+ opts.waitUntil?.(pending);
817
819
  pendingEvaluation = true;
818
820
  }
819
821
  }
@@ -823,7 +825,8 @@ async function valironGateCheck(sdk, opts) {
823
825
  // Detect brand-new key agent: verified but never scored.
824
826
  if (!result.allow && profile.verified && profile.score == null) {
825
827
  if (typeof sdk.triggerKeyAgentSandbox === "function") {
826
- sdk.triggerKeyAgentSandbox(agentAddress).catch(() => { });
828
+ const pending = sdk.triggerKeyAgentSandbox(agentAddress).catch(() => { });
829
+ opts.waitUntil?.(pending);
827
830
  }
828
831
  pendingEvaluation = true;
829
832
  }
@@ -4,7 +4,9 @@ See the [security upgrade guide](SECURITY-UPGRADE-2026-10-31.md) before upgradin
4
4
 
5
5
  [Valiron Crawler Protection](./CRAWLER-PROTECTION.md) runs as a standalone HTTP gateway or in-process middleware with shared admission state. Its private per-deployment work API lets other server languages acquire/release database capacity; it is not part of this hosted public REST API and must remain on private authenticated ingress. The package includes its protocol contract. The website dashboard validates/exports account-scoped configuration without deploying protection and displays optional runtime-reported crawler analytics. Its exports belong to the `@valiron/crawler-protection` package, not `@valiron/sdk`.
6
6
 
7
- SDK 0.2.0+ requires a Free/Pro/Enterprise operator API key and account-bound activation via `activateCrawlerProtection()` before constructing its runtime. Activation uses a short-lived local lease, refreshed in the background. Each protected HTTP request requires hosted monthly quota admission; database operations are not counted again. See the crawler guide for revocation, outage and recovery behavior.
7
+ Crawler SDK 0.3.0+ requires a Free/Pro/Enterprise operator API key and account-bound activation via `activateCrawlerProtection()` before constructing its runtime. Activation uses a short-lived local lease, refreshed in the background. Each protected HTTP request requires hosted monthly quota admission; database operations are not counted again. See the crawler guide for revocation, outage and recovery behavior.
8
+
9
+ For the current crawler integration, install `@valiron/crawler-protection@^0.6.0`. It adds official Anthropic and Google agent/Notebook feeds alongside OpenAI support, and `crawlerAccessDefault` / `unverifiedAccess` configuration. These are customer-runtime controls, not hosted policy-deployment APIs. See [selected AI services and upgrade steps](./CRAWLER-PROTECTION.md#allow-selected-ai-services); source verification does not grant unlimited access or authorize account actions.
8
10
 
9
11
  Machine-readable contract: [Valiron OpenAPI](https://www.valiron.co/openapi.json).
10
12
 
@@ -34,13 +36,11 @@ Hosted gates, proxy forwarding, World ID enrollment and Self session creation al
34
36
  ## Monthly request allowance
35
37
 
36
38
  Free includes **10,000 metered agent requests per account per UTC calendar month**. Pro includes **100,000**. Bot protection has its own allowance of 10,000 on Free and 100,000 on Pro. Enterprise: email founders@valiron.co.
37
- Request 10,000 on Free (100,000 on Pro) is allowed; subsequent requests return HTTP 429 with
38
- `code: "MONTHLY_REQUEST_LIMIT_EXCEEDED"`, `error: "upgrade_required"`, `limit`,
39
- `used`, `resetsAt`, and `upgradeUrl`. Free accounts can upgrade to Pro ($149/month, 100,000 requests per product),
40
- while Pro accounts can email founders@valiron.co for Enterprise, or wait until
41
- the next month at 00:00 UTC. Enterprise allowances are agreed separately; existing feature gates, per-endpoint rate limits and traffic
42
- protections still apply. Crossing the limit never automatically subscribes or
43
- charges an account.
39
+ Request 10,000 on Free (100,000 on Pro) is included. Active paid Pro accounts can explicitly enable additional middleware calls at 0.001 each in their subscription currency. Crawler and middleware allowances, prices and opt-ins are separate. Without an enabled agreement, subsequent calls return HTTP 429 with `code: "MONTHLY_REQUEST_LIMIT_EXCEEDED"`, `error: "upgrade_required"`, `limit`, `used`, `resetsAt` and `upgradeUrl`. Free must upgrade; Pro can enable additional calls in the dashboard or wait for the next UTC month. Crossing a limit never subscribes or opts in an account automatically. Enterprise remains available for custom terms. Feature gates, per-endpoint limits and traffic protections still apply.
40
+
41
+ `GET /operator/usage/billing` returns account-scoped middleware usage, allowance, additional calls and enrollment status using the dashboard session. The website's authenticated `GET /api/middleware/billing` adds the current rate; `POST /api/middleware/billing` accepts `{ "acceptedPriceId": "price_..." }` to opt in to exactly that displayed price. The crawler equivalents remain `/operator/crawlers/billing` and `/api/crawler-protection/billing`. One product's acceptance never opts in the other.
42
+
43
+ Both hosted usage responses include `used`, `included` (`null` for custom Enterprise terms), `overageRequests`, `overagesEnabled`, `needsReview`, `monthStart`, `resetsAt` and `asOf`. `charges` contains accrued request-overage estimates grouped by currency as `{ currency, amount }` entries; `amount` is a decimal string in major currency units. Empty `charges` means no accrued request overages in the current UTC month, not a zero total subscription invoice. Historical accepted terms determine these amounts; optional traffic telemetry and the currently offered rate do not. The website preserves successfully fetched usage if a current-rate lookup fails, returning `price: null` and `priceUnavailable: true`.
44
44
 
45
45
  The shared account allowance counts admitted calls to:
46
46
 
@@ -1010,3 +1010,9 @@ pnpm exec mppx https://valiron-edge-proxy.onrender.com/wrap/{operatorId}/researc
1010
1010
  ## Crawler Protection telemetry (Free / Pro / Enterprise)
1011
1011
 
1012
1012
  `POST /operator/crawlers/telemetry` accepts bounded cumulative reports using a server-side operator API key. `GET /operator/crawlers/analytics` uses the dashboard operator session and returns only that account's rolling origin metrics, instance status, shared capacity and monitoring alerts. Neither endpoint accepts a caller-selected account. Both require current Free/Pro/Enterprise access and return private, non-cacheable responses. Invalid snapshots return 400, authentication failures 401, plan/tenant failures 403, counter/cardinality conflicts 409, excessive reporting frequency 429 and unavailable storage 503. Duplicate or older sequences return `{ "accepted": false }` without adding counts. The first accepted report establishes a baseline. See [reporting setup and limits](./CRAWLER-PROTECTION.md#live-dashboard-analytics). The private work-admission API remains on customer infrastructure.
1013
+
1014
+ Usage billing: website signup and a server-side operator API key are required. Free includes 10,000 requests per product per UTC month; Pro includes 100,000 per product. An active paid Pro subscriber can separately enable additional crawler or middleware calls at 0.001 each in the subscription billing currency, displayed before acceptance. Each product has its own allowance, meter and opt-in. Without opt-in, that product stops at 100,000; Free must upgrade after 10,000. Billing uses durable hosted admission counters, not optional telemetry or every local SDK function call. SDK 0.5.0 also requires account activation for returning-browser recognition.
1015
+
1016
+ ## Crawler managed controls (0.7.0+)
1017
+
1018
+ `createCrawlerControlClient({ configuration, apiKey, site })` adds background policy polling; pass it as `controlClient` to `createCrawlerRuntime`. The dashboard manages crawler access and tighter request budgets within installed ceilings, with publish/rollback, runtime revision acknowledgments, optional bounded recent decision logs and opt-in alerts. It does not deploy customer infrastructure or change work concurrency. Static runtimes are unchanged. See [Dashboard controls](./CRAWLER-PROTECTION.md#dashboard-controls) for the setup, API endpoints, leases and retention limits.