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.

feat(x402): sharpen Forge listing via a shared source of truth

nichf931ba0ea2aa
diff --git a/api/_lib/forge-listing.js b/api/_lib/forge-listing.js
new file mode 100644
index 000000000..764930da3
--- /dev/null
+++ b/api/_lib/forge-listing.js
@@ -0,0 +1,173 @@
+// Forge x402 listing metadata — the SINGLE source of truth for the paid 3D
+// generation endpoint's discovery surface. Both the live 402 challenge
+// (api/x402/forge.js) and the manually-mirrored .well-known/x402.json entry
+// (api/wk.js) import from here, so the listing an agent sees on x402scan /
+// agentic.market / the CDP Bazaar can never drift from what the live 402 quotes.
+//
+// This drift is exactly the bug this module closes: the description, tags,
+// serviceName, and schemas used to live as two hand-kept copies, and the mirror
+// fell out of sync (stale "FLUX→TRELLIS / Base or Solana" copy on a Solana-only,
+// NIM-first endpoint). One export, two importers, zero drift.
+//
+// Pure data + price lookups only — it imports forge-tiers.js (itself dependency-
+// free) so the prices in the prose come from the same constants the 402 quotes,
+// and it pulls in NO provider/LLM/R2 modules, keeping api/wk.js (a lightweight
+// discovery route) cheap to cold-start.
+
+import { priceUsdcForTier } from './forge-tiers.js';
+import { buildBazaarSchema } from './x402-spec.js';
+
+// ── Service metadata (facilitator search rows) ──────────────────────────────
+// serviceName MUST be ≤32 printable-ASCII chars or the CDP Bazaar validator
+// soft-drops it (see scripts/verify-x402-discovery.mjs and bazaar-helpers.js).
+// Kept ASCII on purpose — the em-dash/arrow variant would be silently discarded.
+export const FORGE_SERVICE_NAME = 'three.ws Forge: text/image to 3D'; // 32 chars
+
+// Tags drive x402scan's category facets. These anchor the listing under the
+// three buckets the crown-jewel endpoint belongs in — 3D, AI, and Utility —
+// plus the two concrete modalities agents search for. Capped at 5 (the Bazaar
+// limit); withService()/the mirror both slice to 5, so keep it at 5 exactly.
+export const FORGE_TAGS = Object.freeze(['3d', 'ai', 'text-to-3d', 'image-to-3d', 'utility']);
+
+export const FORGE_ASPECT_RATIOS = Object.freeze(['1:1', '4:3', '3:4', '16:9', '9:16']);
+export const FORGE_MAX_VIEWS = 4;
+
+// Prices sourced from forge-tiers.js so the prose never carries a second copy of
+// a number the 402 could contradict.
+const DRAFT_USD = priceUsdcForTier('draft'); // "0.05"
+const STANDARD_USD = priceUsdcForTier('standard'); // "0.15"
+const HIGH_USD = priceUsdcForTier('high'); // "0.50"
+
+// Leads with the agent use-case (what you build with it), then the tiers +
+// prices, the keyless/no-account pledge, the free poll, and the free draft
+// on-ramp — everything an autonomous buyer needs to decide and to call, in the
+// order they need it. First sentence is the card headline; the rest is detail.
+export const FORGE_ROUTE_DESCRIPTION =
+ 'three.ws Forge — pay-per-call text→3D and image→3D generation for autonomous ' +
+ 'agents. Turn a text prompt (or up to four reference photos of one object) into ' +
+ 'a production-ready GLB mesh for game assets, NFT collections, 3D scenes, and ' +
+ 'product visualization — the only real 3D generation on any agent marketplace. ' +
+ `Three quality tiers in USDC: draft $${DRAFT_USD} (fast low-poly blockout), ` +
+ `standard $${STANDARD_USD} (balanced detail, the default), high $${HIGH_USD} ` +
+ '(maximum geometry + PBR textures). Pay autonomously in USDC on Solana mainnet — ' +
+ 'no API key, no account, no signup. Returns a job token you poll for FREE at ' +
+ 'GET /api/forge?job=<id>; draft prompts often finish inline and hand back the GLB ' +
+ 'url with status:"done". New here? Start on the free keyless draft lane at ' +
+ 'POST /api/3d/generate, then upgrade to a paid tier for standard/high quality or ' +
+ 'image→3D.';
+
+// Example request body surfaced in the discovery UI's "try it" panel.
+export const FORGE_INPUT_EXAMPLE = Object.freeze({
+ prompt: 'a brass steampunk owl, full body',
+ tier: 'standard',
+ aspect_ratio: '1:1',
+});
+
+// Request schema. Complete enough that an agent can call the endpoint from the
+// schema alone: the text prompt, the reference-image (image→3D) mode, the tier
+// selector, and the aspect ratio. The internal health-check canary (mode/type)
+// is intentionally omitted — it is an ops probe, not part of the buyer-facing
+// generation contract, and advertising it only clutters the listing.
+export const FORGE_INPUT_SCHEMA = Object.freeze({
+ $schema: 'https://json-schema.org/draft/2020-12/schema',
+ type: 'object',
+ description:
+ 'Provide exactly one of prompt (text→3D) or image_urls (image→3D). tier and ' +
+ 'aspect_ratio are optional; tier defaults to "standard".',
+ properties: {
+ prompt: {
+ type: 'string',
+ minLength: 3,
+ maxLength: 1000,
+ description: 'Describe one subject for text→3D. Omit when supplying image_urls.',
+ },
+ image_urls: {
+ type: 'array',
+ items: { type: 'string', format: 'uri' },
+ minItems: 1,
+ maxItems: FORGE_MAX_VIEWS,
+ description:
+ 'Up to four public https reference views of one object for image→3D. ' +
+ 'Omit when supplying a prompt.',
+ },
+ tier: {
+ type: 'string',
+ enum: ['draft', 'standard', 'high'],
+ default: 'standard',
+ description:
+ `Quality/price tier: draft $${DRAFT_USD} (low-poly), standard $${STANDARD_USD} ` +
+ `(default), high $${HIGH_USD} (PBR textures). The 402 quotes the price for the ` +
+ 'requested tier.',
+ },
+ aspect_ratio: {
+ type: 'string',
+ enum: [...FORGE_ASPECT_RATIOS],
+ default: '1:1',
+ description: 'Aspect ratio of the synthesized reference view for text→3D.',
+ },
+ },
+});
+
+// Example response. Mirrors exactly what the handler returns for an async job
+// (the free NVIDIA NIM lane accepting a text prompt): a signed poll token, the
+// free poll_url, and the resolved tier/backend/price.
+export const FORGE_OUTPUT_EXAMPLE = Object.freeze({
+ job_id: 'f1.eyJwIjoibnZpZGlhIn0.sig',
+ status: 'queued',
+ poll_url: '/api/forge?job=f1.eyJwIjoibnZpZGlhIn0.sig',
+ mode: 'text_to_3d',
+ tier: 'standard',
+ backend: 'nvidia',
+ eta_seconds: 22,
+ price_usdc: '0.15',
+});
+
+// Response schema. `status` is the only guaranteed field: a queued job carries
+// job_id + poll_url; a job that finishes inside the submit window (the free NIM
+// lane, typical for draft) carries glb_url with status:"done" and a null job_id.
+export const FORGE_OUTPUT_SCHEMA = Object.freeze({
+ $schema: 'https://json-schema.org/draft/2020-12/schema',
+ type: 'object',
+ required: ['status'],
+ properties: {
+ job_id: {
+ type: ['string', 'null'],
+ description: 'Poll this on GET /api/forge?job=<id>. Null when the model finished inline.',
+ },
+ status: { type: 'string', description: '"queued" (poll it) or "done" (glb_url is ready).' },
+ poll_url: {
+ type: ['string', 'null'],
+ description: 'Free, provider-aware status endpoint. Null on inline completion.',
+ },
+ glb_url: {
+ type: 'string',
+ description: 'The finished GLB — present only when status is "done".',
+ },
+ mode: { type: 'string', enum: ['text_to_3d', 'image_to_3d'] },
+ tier: { type: 'string' },
+ backend: { type: 'string' },
+ eta_seconds: { type: 'integer' },
+ price_usdc: { type: 'string' },
+ },
+});
+
+// The complete v2 bazaar discovery block — `{ discoverable, info, schema }`.
+// This is the SINGLE object the live 402 challenge (as ROUTE_BAZAAR) and the
+// api/wk.js discovery mirror both advertise, so the CDP Bazaar / agentic.market
+// / x402scan see byte-identical input+output schemas and examples in both
+// places. `info.output` carries the example; the full input AND output JSON
+// Schemas live in `schema` (built by buildBazaarSchema) so an agent can both
+// call the endpoint and parse its response from the listing alone.
+export const FORGE_BAZAAR = Object.freeze({
+ discoverable: true,
+ info: {
+ input: { type: 'http', method: 'POST', bodyType: 'json', body: FORGE_INPUT_EXAMPLE },
+ output: { type: 'json', example: FORGE_OUTPUT_EXAMPLE },
+ },
+ schema: buildBazaarSchema({
+ method: 'POST',
+ bodyType: 'json',
+ bodySchema: FORGE_INPUT_SCHEMA,
+ outputSchema: FORGE_OUTPUT_SCHEMA,
+ }),
+});
diff --git a/api/x402/forge.js b/api/x402/forge.js
index a792cdca4..51ee9dbf4 100644
--- a/api/x402/forge.js
+++ b/api/x402/forge.js
@@ -40,7 +40,6 @@ import {
encodePaymentResponseHeader,
permit2VariantOf,
resolveResourceUrl,
- buildBazaarSchema,
} from '../_lib/x402-spec.js';
import { env } from '../_lib/env.js';
import { limits, clientIp } from '../_lib/rate-limit.js';
@@ -72,6 +71,15 @@ import {
preferFreeReconstruct,
buildCatalog,
} from '../_lib/forge-tiers.js';
+import {
+ FORGE_SERVICE_NAME,
+ FORGE_TAGS,
+ FORGE_ASPECT_RATIOS,
+ FORGE_MAX_VIEWS,
+ FORGE_ROUTE_DESCRIPTION,
+ FORGE_INPUT_SCHEMA,
+ FORGE_BAZAAR,
+} from '../_lib/forge-listing.js';
import { llmComplete } from '../_lib/llm.js';
const ROUTE = '/api/x402/forge';
@@ -79,9 +87,9 @@ const REQUIRED_SCOPE = 'x402:bypass';
const accessControl = installAccessControl({ requiredScope: REQUIRED_SCOPE });
const routeConfig = { path: ROUTE, method: 'POST', requiredScope: REQUIRED_SCOPE };
-const VALID_ASPECT = new Set(['1:1', '4:3', '3:4', '16:9', '9:16']);
+const VALID_ASPECT = new Set(FORGE_ASPECT_RATIOS);
const HTTP_URL_RE = /^https:\/\/[^\s]+$/i;
-const MAX_VIEWS = 4;
+const MAX_VIEWS = FORGE_MAX_VIEWS;
// The reconstruct lane: serves image→3D (NVIDIA's hosted preview can't take user
// photos) and the text→3D fallback when the free NVIDIA NIM lane is unavailable.
const BACKEND = 'trellis';
@@ -103,108 +111,13 @@ const HEALTH_CHECK_IMAGE_BUDGET_MS = 30_000;
const HEALTH_CHECK_DEFAULT_PROMPT = 'Write one sentence about Solana.';
const HEALTH_CHECK_IMAGE_DEFAULT_PROMPT = 'A simple blue circle.';
-const ROUTE_DESCRIPTION =
- 'three.ws Forge — pay-per-call text→3D and image→3D. Submit a prompt (or up ' +
- 'to four reference views of one object) and get back a job token; poll it for ' +
- 'free at GET /api/forge?job=<id> for the finished GLB (draft prompts often ' +
- 'finish inline and return the GLB url with status:"done"). Text→3D runs on the ' +
- 'free NVIDIA NIM TRELLIS lane (native text→mesh); image→3D reconstructs via ' +
- 'TRELLIS. Priced per quality tier in USDC ($0.05 draft / $0.15 standard / ' +
- '$0.50 high). Pay autonomously in USDC on Solana mainnet — no API key, no account.';
-
-const INPUT_EXAMPLE = {
- prompt: 'a brass steampunk owl, full body',
- tier: 'standard',
- aspect_ratio: '1:1',
-};
-
-const INPUT_SCHEMA = {
- $schema: 'https://json-schema.org/draft/2020-12/schema',
- type: 'object',
- properties: {
- prompt: {
- type: 'string',
- minLength: 3,
- maxLength: 1000,
- description: 'Describe one subject for text→3D. Omit when supplying image_urls.',
- },
- image_urls: {
- type: 'array',
- items: { type: 'string', format: 'uri' },
- minItems: 1,
- maxItems: MAX_VIEWS,
- description: 'Up to four public https reference views of one object for image→3D.',
- },
- tier: { type: 'string', enum: [...TIER_IDS], default: DEFAULT_TIER },
- aspect_ratio: { type: 'string', enum: [...VALID_ASPECT], default: '1:1' },
- mode: {
- type: 'string',
- enum: ['generate', 'health_check'],
- default: 'generate',
- description: 'health_check runs a fast text content-generation canary ($0.001) instead of a 3D job — returns { generated, latency_ms, token_count }.',
- },
- type: {
- type: 'string',
- enum: ['text', 'image'],
- default: 'text',
- description: 'Content type for health_check mode: "text" (LLM completion canary) or "image" (text→image + CDN upload canary).',
- },
- },
-};
-
-const OUTPUT_EXAMPLE = {
- job_id: 'f1.eyJwIjoibnZpZGlhIn0.sig',
- status: 'queued',
- poll_url: '/api/forge?job=f1.eyJwIjoibnZpZGlhIn0.sig',
- mode: 'text_to_3d',
- tier: 'standard',
- backend: 'nvidia',
- eta_seconds: 22,
- price_usdc: '0.15',
-};
-
-const OUTPUT_SCHEMA = {
- $schema: 'https://json-schema.org/draft/2020-12/schema',
- type: 'object',
- // `status` is the only guaranteed field: a queued job carries job_id + poll_url,
- // while a job that completes inside the submit window (the free NVIDIA NIM lane,
- // typical for draft) carries glb_url with status:"done" and a null job_id.
- required: ['status'],
- properties: {
- job_id: {
- type: ['string', 'null'],
- description: 'Poll this on GET /api/forge?job=<id>. Null when the model finished inline.',
- },
- status: { type: 'string', description: '"queued" (poll it) or "done" (glb_url is ready).' },
- poll_url: {
- type: ['string', 'null'],
- description: 'Free, provider-aware status endpoint. Null on inline completion.',
- },
- glb_url: {
- type: 'string',
- description: 'The finished GLB — present only when status is "done".',
- },
- mode: { type: 'string', enum: ['text_to_3d', 'image_to_3d'] },
- tier: { type: 'string' },
- backend: { type: 'string' },
- eta_seconds: { type: 'integer' },
- price_usdc: { type: 'string' },
- },
-};
-
-const ROUTE_BAZAAR = {
- discoverable: true,
- info: {
- input: { type: 'http', method: 'POST', bodyType: 'json', body: INPUT_EXAMPLE },
- output: { type: 'json', example: OUTPUT_EXAMPLE },
- },
- schema: buildBazaarSchema({
- method: 'POST',
- bodyType: 'json',
- bodySchema: INPUT_SCHEMA,
- outputSchema: OUTPUT_SCHEMA,
- }),
-};
+// Discovery/listing metadata is defined once in ../_lib/forge-listing.js and
+// imported by BOTH this live 402 challenge and the api/wk.js discovery mirror, so
+// the two can never drift. Re-exposed under the endpoint's local names to keep
+// the challenge/handler code below unchanged.
+const ROUTE_DESCRIPTION = FORGE_ROUTE_DESCRIPTION;
+const INPUT_SCHEMA = FORGE_INPUT_SCHEMA;
+const ROUTE_BAZAAR = FORGE_BAZAAR;
function buildRequirements(resourceUrl, priceAtomics) {
const amount = String(priceAtomics);
@@ -666,8 +579,8 @@ export default wrap(async (req, res) => {
const priceAtomics = parsed.isHealthCheck ? HEALTH_CHECK_PRICE_ATOMIC : priceAtomicsForTier(parsed.tier);
const requirements = buildRequirements(resourceUrl, priceAtomics);
const service = withService({
- serviceName: 'three.ws Forge — text/image → 3D',
- tags: ['3d', 'generation', 'text-to-3d', 'image-to-3d', 'glb', 'mesh'],
+ serviceName: FORGE_SERVICE_NAME,
+ tags: [...FORGE_TAGS],
});
const challenge = {
resourceUrl,
diff --git a/tests/x402-forge-listing.test.js b/tests/x402-forge-listing.test.js
new file mode 100644
index 000000000..130676ecc
--- /dev/null
+++ b/tests/x402-forge-listing.test.js
@@ -0,0 +1,134 @@
+// Forge (/api/x402/forge) — discovery listing quality + schema completeness.
+//
+// Forge is the platform's crown-jewel paid endpoint (real text→3D / image→3D),
+// so its x402scan / CDP Bazaar listing has to sell the use-case AND be complete
+// enough that an autonomous agent can call it blind. The description, tags,
+// serviceName, and input/output schemas all live in ONE place —
+// api/_lib/forge-listing.js — imported by both the live 402 challenge
+// (api/x402/forge.js) and the discovery mirror (api/wk.js), so the two can't
+// drift. These tests lock that shared contract down:
+// 1. the description leads with the use-case and quotes the tiers/prices,
+// the keyless pledge, the free poll, and the free draft on-ramp,
+// 2. the tags anchor the 3D / AI / Utility categories within the Bazaar's
+// 5-tag, ≤32-ASCII limits,
+// 3. serviceName is ≤32 printable ASCII (or the CDP validator soft-drops it),
+// 4. the input schema names every call field (prompt, reference-image mode,
+// tier, aspect ratio) and the output schema documents the poll token + GLB,
+// 5. the published input/output examples satisfy their own schemas.
+//
+// The bazaar.info ⇄ bazaar.schema self-validation (CDP-acceptance) is covered
+// end-to-end by scripts/verify-x402-discovery.mjs against the discovery doc, so
+// it is not re-checked here — which lets us mock the heavy x402-spec leaf (it
+// transitively pulls the CDP SDK + Solana client this test doesn't need).
+
+import { describe, it, expect, vi } from 'vitest';
+import Ajv2020 from 'ajv/dist/2020.js';
+import addFormats from 'ajv-formats';
+
+vi.mock('../api/_lib/x402-spec.js', () => ({ buildBazaarSchema: () => ({}) }));
+
+const {
+ FORGE_SERVICE_NAME,
+ FORGE_TAGS,
+ FORGE_ROUTE_DESCRIPTION,
+ FORGE_INPUT_SCHEMA,
+ FORGE_OUTPUT_SCHEMA,
+ FORGE_INPUT_EXAMPLE,
+ FORGE_OUTPUT_EXAMPLE,
+ FORGE_BAZAAR,
+} = await import('../api/_lib/forge-listing.js');
+
+const ajv = new Ajv2020({ allErrors: true, strict: false });
+addFormats(ajv);
+
+const isPrintableAscii = (s, max) =>
+ typeof s === 'string' && s.length > 0 && s.length <= max && /^[\x20-\x7e]+$/.test(s);
+
+describe('forge listing — description sells the use-case + funnel', () => {
+ it('leads with the concrete agent use-cases', () => {
+ expect(FORGE_ROUTE_DESCRIPTION).toMatch(/game asset/i);
+ expect(FORGE_ROUTE_DESCRIPTION).toMatch(/NFT/i);
+ expect(FORGE_ROUTE_DESCRIPTION).toMatch(/scene/i);
+ expect(FORGE_ROUTE_DESCRIPTION).toMatch(/product vis/i);
+ });
+
+ it('quotes all three quality tiers and their prices', () => {
+ expect(FORGE_ROUTE_DESCRIPTION).toMatch(/draft \$0\.05/);
+ expect(FORGE_ROUTE_DESCRIPTION).toMatch(/standard \$0\.15/);
+ expect(FORGE_ROUTE_DESCRIPTION).toMatch(/high \$0\.50/);
+ });
+
+ it('makes the keyless / no-account pledge and names Solana settlement', () => {
+ expect(FORGE_ROUTE_DESCRIPTION).toMatch(/no API key/i);
+ expect(FORGE_ROUTE_DESCRIPTION).toMatch(/no account/i);
+ expect(FORGE_ROUTE_DESCRIPTION).toMatch(/Solana/);
+ });
+
+ it('wires the free poll and the free draft on-ramp', () => {
+ expect(FORGE_ROUTE_DESCRIPTION).toContain('/api/forge?job=');
+ expect(FORGE_ROUTE_DESCRIPTION).toContain('/api/3d/generate');
+ });
+});
+
+describe('forge listing — service metadata within Bazaar limits', () => {
+ it('serviceName is ≤32 printable ASCII (CDP soft-drop rule)', () => {
+ expect(isPrintableAscii(FORGE_SERVICE_NAME, 32)).toBe(true);
+ });
+
+ it('has ≤5 printable-ASCII tags anchoring the 3D / AI / Utility categories', () => {
+ expect(Array.isArray(FORGE_TAGS)).toBe(true);
+ expect(FORGE_TAGS.length).toBeLessThanOrEqual(5);
+ for (const t of FORGE_TAGS) expect(isPrintableAscii(t, 32)).toBe(true);
+ expect(FORGE_TAGS).toEqual(expect.arrayContaining(['3d', 'ai', 'utility']));
+ });
+});
+
+describe('forge listing — schema completeness (call it blind)', () => {
+ it('input schema names every generation field', () => {
+ const p = FORGE_INPUT_SCHEMA.properties;
+ expect(p.prompt).toBeTruthy(); // text→3D
+ expect(p.image_urls).toBeTruthy(); // image→3D (reference views)
+ expect(p.image_urls.maxItems).toBe(4);
+ expect(p.tier.enum).toEqual(['draft', 'standard', 'high']);
+ expect(p.aspect_ratio.enum).toContain('1:1');
+ });
+
+ it('does NOT advertise the internal health-check canary in the public listing', () => {
+ expect(FORGE_INPUT_SCHEMA.properties.mode).toBeUndefined();
+ expect(FORGE_INPUT_SCHEMA.properties.type).toBeUndefined();
+ });
+
+ it('output schema documents the poll token and the GLB output', () => {
+ expect(FORGE_OUTPUT_SCHEMA.required).toContain('status');
+ const p = FORGE_OUTPUT_SCHEMA.properties;
+ expect(p.job_id).toBeTruthy();
+ expect(p.poll_url).toBeTruthy();
+ expect(p.glb_url).toBeTruthy();
+ expect(p.mode.enum).toEqual(['text_to_3d', 'image_to_3d']);
+ });
+
+ it('the published input example satisfies FORGE_INPUT_SCHEMA', () => {
+ const validate = ajv.compile(FORGE_INPUT_SCHEMA);
+ const ok = validate(FORGE_INPUT_EXAMPLE);
+ expect(validate.errors, JSON.stringify(validate.errors)).toBeNull();
+ expect(ok).toBe(true);
+ });
+
+ it('the published output example satisfies FORGE_OUTPUT_SCHEMA', () => {
+ const validate = ajv.compile(FORGE_OUTPUT_SCHEMA);
+ const ok = validate(FORGE_OUTPUT_EXAMPLE);
+ expect(validate.errors, JSON.stringify(validate.errors)).toBeNull();
+ expect(ok).toBe(true);
+ });
+});
+
+describe('forge listing — the shared bazaar block is what both surfaces advertise', () => {
+ it('info carries the input body + output example examples verbatim', () => {
+ expect(FORGE_BAZAAR.discoverable).toBe(true);
+ expect(FORGE_BAZAAR.info.input.method).toBe('POST');
+ expect(FORGE_BAZAAR.info.input.body).toEqual(FORGE_INPUT_EXAMPLE);
+ expect(FORGE_BAZAAR.info.output.example).toEqual(FORGE_OUTPUT_EXAMPLE);
+ // The response example includes the resolved backend so result cards render it.
+ expect(FORGE_BAZAAR.info.output.example.backend).toBe('nvidia');
+ });
+});