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(x402): cap the PAYMENT-REQUIRED mirror at 7 KB, because production strips an 8 KB header

nirholasdfeb09d41319
diff --git a/api/_lib/x402-spec.js b/api/_lib/x402-spec.js
index 8a94a1afc..d7685933b 100644
--- a/api/_lib/x402-spec.js
+++ b/api/_lib/x402-spec.js
@@ -1642,8 +1642,16 @@ export async function build402Body({
// (HEADERS_OVERFLOW, "some clients will fail to parse this response").
// Endpoints with rich bazaar schemas + per-accept signed offers were
// emitting 11-17 KB headers, which the production LB then dropped entirely.
-// 8 KB leaves comfortable room for the ~0.5 KB of ordinary headers.
-const PAYMENT_REQUIRED_HEADER_MAX = 8 * 1024;
+//
+// The cap itself was then too close to the edge. On 2026-09-18 production
+// delivered a 7,760-byte mirror (/api/x402/forge) but silently stripped an
+// 8,192-byte one (/api/x402/pump-launch, which landed exactly on the old 8 KB
+// cap), so that route answered 402 with no PAYMENT-REQUIRED header at all and
+// marketplace validators failed it. 7 KB sits below every size observed to
+// survive and leaves headroom for the other response headers to grow. The body
+// always carries the complete challenge, so a smaller mirror loses nothing a
+// client needs.
+export const PAYMENT_REQUIRED_HEADER_MAX = 7 * 1024;
const isPlainRecord = (v) => v != null && typeof v === 'object' && !Array.isArray(v);
diff --git a/tests/api/x402-spec.test.js b/tests/api/x402-spec.test.js
index 459a31443..225631914 100644
--- a/tests/api/x402-spec.test.js
+++ b/tests/api/x402-spec.test.js
@@ -620,10 +620,10 @@ describe('send402 PAYMENT-REQUIRED header', () => {
});
it('keeps the full bazaar (info + schema) when a schema-bearing envelope fits', async () => {
- const { paymentRequiredHeaderValue } = await loadSpec();
+ const { paymentRequiredHeaderValue, PAYMENT_REQUIRED_HEADER_MAX } = await loadSpec();
const body = envelopeWithBazaarSchema();
const header = paymentRequiredHeaderValue(body);
- expect(header.length).toBeLessThanOrEqual(8 * 1024);
+ expect(header.length).toBeLessThanOrEqual(PAYMENT_REQUIRED_HEADER_MAX);
const decoded = JSON.parse(Buffer.from(header, 'base64').toString('utf8'));
// Full envelope fit — bazaar and its info both survive verbatim.
expect(decoded.extensions.bazaar.info).toBeDefined();
@@ -632,10 +632,10 @@ describe('send402 PAYMENT-REQUIRED header', () => {
});
it('drops the bazaar info examples (keeping the real schema) when the full mirror overflows', async () => {
- const { paymentRequiredHeaderValue } = await loadSpec();
+ const { paymentRequiredHeaderValue, PAYMENT_REQUIRED_HEADER_MAX } = await loadSpec();
const body = envelopeWithBazaarSchema({ infoBytes: 20_000 });
const header = paymentRequiredHeaderValue(body);
- expect(header.length).toBeLessThanOrEqual(8 * 1024);
+ expect(header.length).toBeLessThanOrEqual(PAYMENT_REQUIRED_HEADER_MAX);
const decoded = JSON.parse(Buffer.from(header, 'base64').toString('utf8'));
// Heavy payment extensions and the bloated info are gone; the machine
// schema the discovery crawler needs stays, verbatim.
@@ -647,10 +647,10 @@ describe('send402 PAYMENT-REQUIRED header', () => {
});
it('compacts the bazaar field schemas when even the schema alone overflows', async () => {
- const { paymentRequiredHeaderValue } = await loadSpec();
+ const { paymentRequiredHeaderValue, PAYMENT_REQUIRED_HEADER_MAX } = await loadSpec();
const body = envelopeWithBazaarSchema({ fieldBytes: 20_000 });
const header = paymentRequiredHeaderValue(body);
- expect(header.length).toBeLessThanOrEqual(8 * 1024);
+ expect(header.length).toBeLessThanOrEqual(PAYMENT_REQUIRED_HEADER_MAX);
const decoded = JSON.parse(Buffer.from(header, 'base64').toString('utf8'));
// Field schemas collapse to a compact `{type:'object'}` placeholder,
// but input/output presence — all the crawler keys on — survives.
@@ -661,13 +661,21 @@ describe('send402 PAYMENT-REQUIRED header', () => {
expect(discoverySchemasResolvable(decoded)).toBe(true);
});
+ it('keeps the mirror under the size production is known to strip', async () => {
+ // 2026-09-18: a 7,760-byte mirror reached clients, an 8,192-byte one was
+ // removed in transit and its route answered 402 with no header at all.
+ const { PAYMENT_REQUIRED_HEADER_MAX } = await loadSpec();
+ expect(PAYMENT_REQUIRED_HEADER_MAX).toBeLessThan(8192);
+ expect(PAYMENT_REQUIRED_HEADER_MAX).toBeLessThanOrEqual(7760);
+ });
+
it('falls to an extension-less slim mirror when no bazaar tier fits', async () => {
- const { paymentRequiredHeaderValue } = await loadSpec();
+ const { paymentRequiredHeaderValue, PAYMENT_REQUIRED_HEADER_MAX } = await loadSpec();
// Schema-less bazaar that is itself far too big — no discovery tier
// can shrink it, so only the payable slim envelope survives.
const body = envelopeWithExtensions(20_000);
const header = paymentRequiredHeaderValue(body);
- expect(header.length).toBeLessThanOrEqual(8 * 1024);
+ expect(header.length).toBeLessThanOrEqual(PAYMENT_REQUIRED_HEADER_MAX);
const decoded = JSON.parse(Buffer.from(header, 'base64').toString('utf8'));
expect(decoded.extensions).toBeUndefined();
// Everything a header-only payer needs survives.