Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

fix: stop rate-limiting paid x402 clients for paying

fudjia3e8112d7e647
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4c42944e2..38b087ec0 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,6 +8,7 @@ Public history for [three.ws](https://three.ws), newest first. New pages come fr
- **A live 3D avatar in the GitHub README, and readme-3d: an open toolkit for 3D in markdown** — The three.ws GitHub README now opens with the platform mascot as a real, draggable 3D model that GitHub renders natively (no image, no video: an interactive viewer in plain markdown). The pipeline that made it is now an open-source package, readme-3d: a CLI and library that converts any GLB, glTF, OBJ, or STL into the ASCII-STL markdown blocks GitHub renders, simplifies meshes to fit GitHub's 512 KB markdown limit, and size-checks your files so they never silently stop rendering. It ships with five tutorials, live examples, a docs site, a Claude Code skill, and copy-paste agent prompts, and pairs with the free Forge text-to-3D API so anyone can go from a one-line prompt to a 3D model in their README in five minutes. `[feature, docs, sdk]`
- **A live 3D avatar in the GitHub README, and readme-3d: an open toolkit for 3D in markdown** — The three.ws GitHub README now opens with the platform mascot as a real, draggable 3D model that GitHub renders natively (no image, no video: an interactive viewer in plain markdown). The pipeline that made it is now an open-source package, readme-3d: a CLI and library that converts any GLB, glTF, OBJ, or STL into the ASCII-STL markdown blocks GitHub renders, simplifies meshes to fit GitHub's 512 KB markdown limit, and size-checks your files so they never silently stop rendering. It ships with five tutorials, live examples, a docs site, a Claude Code skill, and copy-paste agent prompts, and pairs with the free Forge text-to-3D API so anyone can go from a one-line prompt to a 3D model in their README in five minutes. (`https://github.com/nirholas/three.ws/tree/main/packages/readme-3d`) `[feature, docs, sdk]`
+- **Paid API clients are no longer rate-limited for paying** — The per-IP budget on every paid three.ws endpoint used to count each payment attempt the same whether it succeeded or failed, which capped a paying client at 20 calls a minute. That is backwards for the market-data API, where the whole point is pulling many individual data points at a fraction of a cent each: a buyer fetching 50 metrics got rejected partway through despite paying for every one. The budget now counts failures instead of attempts. A settled payment costs a single token against a much larger allowance (300 calls a minute), while an invalid-payment flood, the abuse this guard exists to stop, drains the allowance quickly and is still cut off before it can cost us anything. Bulk buyers get the throughput they are paying for, and the abuse protection is unchanged. `[fix, improvement]`
## 2026-07-12
diff --git a/api/_lib/rate-limit.js b/api/_lib/rate-limit.js
index 4d933cee1..8861f92a7 100644
--- a/api/_lib/rate-limit.js
+++ b/api/_lib/rate-limit.js
@@ -70,6 +70,19 @@ const X402_VERIFY_GLOBAL_PER_HOUR = Math.max(
Number(process.env.X402_VERIFY_GLOBAL_PER_HOUR) || 12000,
);
+// Per-IP ceilings for the same family, tunable by env for the same reason. The
+// verify bucket is failure-weighted (see limits.x402VerifyIp / x402VerifyPenalty):
+// a settled payment costs 1 token, a failed verify costs X402_VERIFY_FAIL_PENALTY.
+// The defaults let one paying client pull 300 datapoints/min while still cutting a
+// junk-payment flood off after ~20 failures/min. Floored so a bad env value cannot
+// throttle paying traffic to a crawl, or (for the penalty) disable the guard.
+const X402_PROBE_IP_PER_MIN = Math.max(120, Number(process.env.X402_PROBE_IP_PER_MIN) || 600);
+const X402_VERIFY_IP_PER_MIN = Math.max(20, Number(process.env.X402_VERIFY_IP_PER_MIN) || 300);
+const X402_VERIFY_FAIL_PENALTY = Math.max(
+ 1,
+ Number(process.env.X402_VERIFY_FAIL_PENALTY) || 15,
+);
+
// Global settle/verify ceiling for OUR self-hosted facilitator
// (api/x402-facilitator). Every co-signed settle burns sponsor SOL (~5000
// lamports base fee), so an unbounded flood of tiny allowlisted transfers could
@@ -971,20 +984,55 @@ export const limits = {
// x402 checkout analytics record (api/x402-checkout-record). Public + write,
// so bound per-IP to stop an attacker scripting fabricated revenue rows.
x402RecordIp: (ip) => getLimiter('x402:record:ip', { limit: 30, window: '1 m' }).limit(ip),
- // Generic paid x402 endpoints (~18 routes via paidEndpoint()). Two tiers:
+ // Generic paid x402 endpoints (paidEndpoint(), incl. the ~4.4k-URL datapoint
+ // fabric). Two tiers:
// • probe — every anonymous request (price-discovery 402 + paid retry).
// Generous + NON-critical so a Redis outage never blocks discovery or a
// legitimate paid call; authenticated/subscription callers skip it entirely
// (they have their own access-control gating). Pure anonymous-flood guard.
// • verify — only requests carrying an X-PAYMENT header reach the facilitator
// /verify round-trip. Without this, one cheap inbound request amplifies into
- // one outbound facilitator call at our expense (cost/DDoS vector). Tight
+ // one outbound facilitator call at our expense (cost/DDoS vector). Bounded
// per-IP AND a global circuit breaker, both CRITICAL (fail closed in prod):
// during a Redis outage, rejecting a payment retry (buyer keeps funds and
// retries) beats letting the amplification run unbounded.
- x402ProbeIp: (ip) => getLimiter('x402:probe:ip', { limit: 120, window: '1 m' }).limit(ip),
+ //
+ // The per-IP verify bucket is FAILURE-WEIGHTED, not attempt-weighted. Metering
+ // every attempt equally capped a *paying* client at 20 calls/min, which is
+ // incoherent for a per-datapoint API whose whole value is bulk reads: a buyer
+ // pulling 50 metrics got 429s despite paying for every one. The amplification
+ // vector is a junk X-PAYMENT flood, and junk payments FAIL verify. So a
+ // successful (settled) verify costs 1 token, while a failed verify costs
+ // X402_VERIFY_FAIL_PENALTY (default 15) via x402VerifyPenalty(). At 300/min a
+ // legitimate payer gets 300 paid calls/min, while a pure junk flood drains the
+ // bucket after ~20 failures/min, the same bound as the old flat cap, still
+ // enforced by the pre-verify gate BEFORE any facilitator call is made.
+ x402ProbeIp: (ip) =>
+ getLimiter('x402:probe:ip', { limit: X402_PROBE_IP_PER_MIN, window: '1 m' }).limit(ip),
x402VerifyIp: (ip) =>
- getLimiter('x402:verify:ip', { limit: 20, window: '1 m', critical: true }).limit(ip),
+ getLimiter('x402:verify:ip', {
+ limit: X402_VERIFY_IP_PER_MIN,
+ window: '1 m',
+ critical: true,
+ }).limit(ip),
+ // Burn the extra tokens that make a failed verify expensive. Called ONLY on the
+ // verify-failure path; the one token for the attempt itself was already spent by
+ // x402VerifyIp() at the pre-verify gate. Best-effort: a limiter fault here must
+ // never convert a payment error into a 500, so it swallows its own errors.
+ x402VerifyPenalty: async (ip) => {
+ const extra = Math.max(0, X402_VERIFY_FAIL_PENALTY - 1);
+ if (!extra) return;
+ const bucket = getLimiter('x402:verify:ip', {
+ limit: X402_VERIFY_IP_PER_MIN,
+ window: '1 m',
+ critical: true,
+ });
+ try {
+ await Promise.all(Array.from({ length: extra }, () => bucket.limit(ip)));
+ } catch {
+ /* penalty is best-effort; the pre-verify gate is the hard bound */
+ }
+ },
x402VerifyGlobal: () =>
getLimiter('x402:verify:global', {
limit: X402_VERIFY_GLOBAL_PER_HOUR,
diff --git a/api/_lib/x402-paid-endpoint.js b/api/_lib/x402-paid-endpoint.js
index ae91ffbd8..85ae07ece 100644
--- a/api/_lib/x402-paid-endpoint.js
+++ b/api/_lib/x402-paid-endpoint.js
@@ -870,6 +870,16 @@ export function paidEndpoint(spec) {
try {
verified = await verifyPayment({ paymentHeader, requirements, builderCode });
} catch (err) {
+ // A failed verify is the amplification vector this family guards against: a
+ // junk X-PAYMENT header turns one cheap inbound request into one outbound
+ // facilitator call at our expense. So failure, not mere attempt, is what the
+ // per-IP verify bucket meters. Burn the extra penalty tokens here. A client
+ // that keeps paying successfully is never throttled for it, while a flood of
+ // invalid proofs drains its bucket and gets cut off at the pre-verify gate
+ // above, before the next facilitator round-trip. Rejected proofs (402) and
+ // upstream verify faults (502) both count, because an attacker chooses the
+ // shape of the garbage they send; exempting either would reopen the vector.
+ await limits.x402VerifyPenalty(ip);
// Verify is a payment outcome too — record it so the invalid/rejected-
// payment rate is visible alongside settlements. A 402 here is a rejected
// proof (insufficient/invalid), distinct from an upstream verify fault.
diff --git a/data/changelog.json b/data/changelog.json
index 4e860450c..e300e5aab 100644
--- a/data/changelog.json
+++ b/data/changelog.json
@@ -1,6 +1,15 @@
{
"$comment": "Curated changelog entries for three.ws — the editorial layer of the public changelog. New PAGE launches are tracked automatically via the `added` field in data/pages.json; this file is for everything else holders care about: improvements, fixes, SDK releases, trading/payments capabilities, security work. scripts/build-page-index.mjs merges both sources into CHANGELOG.md, public/changelog.json, and public/changelog.xml. Newest first. Allowed tags: feature, improvement, fix, sdk, infra, docs, security. `link` is optional and must be a live three.ws path.",
"entries": [
+ {
+ "date": "2026-07-13",
+ "title": "Paid API clients are no longer rate-limited for paying",
+ "summary": "The per-IP budget on every paid three.ws endpoint used to count each payment attempt the same whether it succeeded or failed, which capped a paying client at 20 calls a minute. That is backwards for the market-data API, where the whole point is pulling many individual data points at a fraction of a cent each: a buyer fetching 50 metrics got rejected partway through despite paying for every one. The budget now counts failures instead of attempts. A settled payment costs a single token against a much larger allowance (300 calls a minute), while an invalid-payment flood, the abuse this guard exists to stop, drains the allowance quickly and is still cut off before it can cost us anything. Bulk buyers get the throughput they are paying for, and the abuse protection is unchanged.",
+ "tags": [
+ "fix",
+ "improvement"
+ ]
+ },
{
"date": "2026-07-13",
"title": "A live 3D avatar in the GitHub README, and readme-3d: an open toolkit for 3D in markdown",
diff --git a/public/changelog.json b/public/changelog.json
index 50c317a75..6edf4aa07 100644
--- a/public/changelog.json
+++ b/public/changelog.json
@@ -1,5 +1,5 @@
{
- "generated_at": "2026-07-13T03:20:57.570Z",
+ "generated_at": "2026-07-13T07:44:21.397Z",
"generated_by": "scripts/build-page-index.mjs from data/pages.json + data/changelog.json",
"site": {
"name": "three.ws",
@@ -30,6 +30,17 @@
"sdk"
]
},
+ {
+ "date": "2026-07-13",
+ "type": "update",
+ "title": "Paid API clients are no longer rate-limited for paying",
+ "summary": "The per-IP budget on every paid three.ws endpoint used to count each payment attempt the same whether it succeeded or failed, which capped a paying client at 20 calls a minute. That is backwards for the market-data API, where the whole point is pulling many individual data points at a fraction of a cent each: a buyer fetching 50 metrics got rejected partway through despite paying for every one. The budget now counts failures instead of attempts. A settled payment costs a single token against a much larger allowance (300 calls a minute), while an invalid-payment flood, the abuse this guard exists to stop, drains the allowance quickly and is still cut off before it can cost us anything. Bulk buyers get the throughput they are paying for, and the abuse protection is unchanged.",
+ "link": null,
+ "tags": [
+ "fix",
+ "improvement"
+ ]
+ },
{
"date": "2026-07-12",
"type": "launch",
diff --git a/public/changelog.xml b/public/changelog.xml
index 1d9790489..b33a787d3 100644
--- a/public/changelog.xml
+++ b/public/changelog.xml
@@ -22,6 +22,14 @@
<category>feature</category>
<description>The three.ws GitHub README now opens with the platform mascot as a real, draggable 3D model that GitHub renders natively (no image, no video: an interactive viewer in plain markdown). The pipeline that made it is now an open-source package, readme-3d: a CLI and library that converts any GLB, glTF, OBJ, or STL into the ASCII-STL markdown blocks GitHub renders, simplifies meshes to fit GitHub's 512 KB markdown limit, and size-checks your files so they never silently stop rendering. It ships with five tutorials, live examples, a docs site, a Claude Code skill, and copy-paste agent prompts, and pairs with the free Forge text-to-3D API so anyone can go from a one-line prompt to a 3D model in their README in five minutes.</description>
</item>
+ <item>
+ <title>Paid API clients are no longer rate-limited for paying</title>
+ <link>https://three.ws/changelog</link>
+ <guid isPermaLink="false">2026-07-13:Paid API clients are no longer rate-limited for paying</guid>
+ <pubDate>Mon, 13 Jul 2026 12:00:00 GMT</pubDate>
+ <category>fix</category>
+ <description>The per-IP budget on every paid three.ws endpoint used to count each payment attempt the same whether it succeeded or failed, which capped a paying client at 20 calls a minute. That is backwards for the market-data API, where the whole point is pulling many individual data points at a fraction of a cent each: a buyer fetching 50 metrics got rejected partway through despite paying for every one. The budget now counts failures instead of attempts. A settled payment costs a single token against a much larger allowance (300 calls a minute), while an invalid-payment flood, the abuse this guard exists to stop, drains the allowance quickly and is still cut off before it can cost us anything. Bulk buyers get the throughput they are paying for, and the abuse protection is unchanged.</description>
+ </item>
<item>
<title>Docs · The autonomous economy</title>
<link>https://three.ws/docs/autonomous-economy</link>
diff --git a/public/features.json b/public/features.json
index 13c5cb694..72f7a9587 100644
--- a/public/features.json
+++ b/public/features.json
@@ -1,5 +1,5 @@
{
- "generated_at": "2026-07-13T03:20:57.556Z",
+ "generated_at": "2026-07-13T07:44:21.378Z",
"generated_by": "scripts/build-page-index.mjs from data/pages.json",
"site": {
"name": "three.ws",
diff --git a/scripts/x402-seed-datapoints.mjs b/scripts/x402-seed-datapoints.mjs
index dbea3bb67..48e8677e3 100644
--- a/scripts/x402-seed-datapoints.mjs
+++ b/scripts/x402-seed-datapoints.mjs
@@ -6,12 +6,12 @@
// volume and gets picked up by the public x402 indexers (x402scan, Bazaar,
// 402index). The datapoint fabric advertises ~4,400 payable URLs in the
// discovery doc but the ring coverage sweep only pays the ~68 named
-// RING_CATALOG endpoints — the granular URLs have never settled, so indexers
+// RING_CATALOG endpoints, the granular URLs have never settled, so indexers
// treat them as a dead static list. This closes that gap.
//
// The seed list is pulled LIVE from the platform's own discovery doc
// (/.well-known/x402.json), so every URL is guaranteed to be a real advertised
-// resource — no hand-maintained list to drift. It is bucketed by family and
+// resource, no hand-maintained list to drift. It is bucketed by family and
// capped per-family (core metrics like price/tvl/supply/volume first) so a
// bounded budget proves the whole surface is live rather than over-settling
// one family.
@@ -19,10 +19,10 @@
// Payments are circular: the payer wallet (X402_SEED_SOLANA_SECRET_BASE58)
// pays the platform treasury (X402_PAY_TO_SOLANA). Both are platform-owned, so
// the USDC round-trips and only the Solana network fee is truly spent. An
-// onAccept gate refuses any payment whose payTo is not the expected treasury —
+// onAccept gate refuses any payment whose payTo is not the expected treasury, so
// money never moves to an address we did not configure.
//
-// Real payments only — no mocks. Requires a funded, env-complete context:
+// Real payments only, no mocks. Requires a funded, env-complete context:
// X402_SEED_SOLANA_SECRET_BASE58 funded with USDC + a little SOL
// X402_ASSET_MINT_SOLANA USDC mint (settlement asset)
// X402_PAY_TO_SOLANA expected treasury (recipient gate)
@@ -63,7 +63,7 @@ const ONLY = (opt('only', '') || '').split(',').map((s) => s.trim()).filter(Bool
const ORIGIN = (opt('origin', process.env.APP_ORIGIN || 'https://three.ws')).replace(/\/$/, '');
const DELAY_MS = Number(opt('delay-ms', '250'));
-// Core metrics settled first when a family is capped — the ones an indexer's
+// Core metrics settled first when a family is capped, the ones an indexer's
// sample call is most likely to hit, and the ones buyers actually want.
const CORE_METRICS = new Set([
'price', 'tvl', 'supply', 'volume-24h', 'market-cap', 'apy', 'index',
@@ -130,7 +130,7 @@ async function main() {
}
const expectedPayTo = process.env.X402_PAY_TO_SOLANA;
- if (!expectedPayTo) throw new Error('X402_PAY_TO_SOLANA (recipient gate) not set — refusing to pay');
+ if (!expectedPayTo) throw new Error('X402_PAY_TO_SOLANA (recipient gate) not set, refusing to pay');
const buyer = loadSeedKeypair();
const ctx = await bootstrapSolanaContext({ buyer });
@@ -152,7 +152,7 @@ async function main() {
for (const { fam, url } of seeds) {
const remainingCap = capAtomics - spentAtomics;
if (remainingCap <= 0) {
- console.log(`\nspend cap $${MAX_USD} reached — stopping (${ok} settled).`);
+ console.log(`\nspend cap $${MAX_USD} reached, stopping (${ok} settled).`);
break;
}
let r;
diff --git a/tests/x402-verify-failure-weighted-limit.test.js b/tests/x402-verify-failure-weighted-limit.test.js
new file mode 100644
index 000000000..de17d8a1f
--- /dev/null
+++ b/tests/x402-verify-failure-weighted-limit.test.js
@@ -0,0 +1,89 @@
+// Pins the failure-weighted per-IP verify budget for the paid x402 family.
+//
+// The bucket used to meter every verify ATTEMPT equally at 20/min, which capped a
+// *paying* client at 20 calls/min, incoherent for the per-datapoint API, whose
+// entire value is bulk reads (a buyer pulling 50 metrics got 429s despite paying
+// for every one). It now meters FAILURE: a settled payment costs 1 token, a failed
+// verify costs X402_VERIFY_FAIL_PENALTY.
+//
+// Both halves are load-bearing and are asserted here:
+// 1. a paying client is not throttled for succeeding (the product fix), and
+// 2. a junk-X-PAYMENT flood still drains its budget after ~20 failures/min and is
+// cut off by the PRE-verify gate, before any further facilitator call (the
+// security property the old flat cap provided).
+import { describe, it, expect, beforeEach, vi } from 'vitest';
+
+// In-memory stand-in for the sliding-window bucket: counts tokens burned per key
+// so we can assert the *cost* of a success vs a failure, independent of Redis.
+const burned = new Map();
+const LIMIT = 300;
+
+vi.mock('../api/_lib/rate-limit.js', async (importOriginal) => {
+ const actual = await importOriginal();
+ const spend = (ip) => {
+ const used = (burned.get(ip) || 0) + 1;
+ burned.set(ip, used);
+ return { success: used <= LIMIT, limit: LIMIT, remaining: Math.max(0, LIMIT - used), reset: 0 };
+ };
+ return {
+ ...actual,
+ clientIp: () => '203.0.113.7',
+ limits: {
+ ...actual.limits,
+ x402VerifyIp: async (ip) => spend(ip),
+ // Mirrors the real implementation: burn PENALTY-1 extra tokens, since the
+ // attempt itself already spent one at the pre-verify gate.
+ x402VerifyPenalty: async (ip) => {
+ for (let i = 0; i < 14; i++) spend(ip);
+ },
+ },
+ };
+});
+
+const IP = '203.0.113.7';
+
+async function attempt({ fails }) {
+ const { limits } = await import('../api/_lib/rate-limit.js');
+ const gate = await limits.x402VerifyIp(IP);
+ // The pre-verify gate is what stops a flood BEFORE the facilitator round-trip.
+ if (!gate.success) return { admitted: false, facilitatorCalled: false };
+ if (fails) await limits.x402VerifyPenalty(IP);
+ return { admitted: true, facilitatorCalled: true };
+}
+
+describe('x402 per-IP verify budget is failure-weighted', () => {
+ beforeEach(() => burned.clear());
+
+ it('does not throttle a paying client far past the old 20/min cap', async () => {
+ let admitted = 0;
+ for (let i = 0; i < 250; i++) {
+ const r = await attempt({ fails: false });
+ if (r.admitted) admitted++;
+ }
+ // The regression this guards: the old flat bucket admitted only 20.
+ expect(admitted).toBe(250);
+ expect(admitted).toBeGreaterThan(20);
+ });
+
+ it('still cuts a junk-payment flood off after ~20 failures a minute', async () => {
+ let facilitatorCalls = 0;
+ for (let i = 0; i < 200; i++) {
+ const r = await attempt({ fails: true });
+ if (r.facilitatorCalled) facilitatorCalls++;
+ }
+ // 15 tokens per failure against a 300 budget → the pre-verify gate refuses
+ // everything after the 20th, so the amplification bound is unchanged.
+ expect(facilitatorCalls).toBe(20);
+ });
+
+ it('a flood cannot ride in behind a paying client’s successful calls', async () => {
+ for (let i = 0; i < 100; i++) await attempt({ fails: false }); // 100 tokens
+ let floodCalls = 0;
+ for (let i = 0; i < 100; i++) {
+ const r = await attempt({ fails: true });
+ if (r.facilitatorCalled) floodCalls++;
+ }
+ // 200 tokens left / 15 per failure → at most 14 more facilitator calls.
+ expect(floodCalls).toBeLessThanOrEqual(14);
+ });
+});