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.
JavaScript 3d-generationai-agentsanimationavatardigital-humangenerative-aiglbgltfimage-to-3dllmmcpmcp-servermodel-context-protocolsolanatext-to-3dthreejsweb-componentswebglwebxrx402
Attribute free 3D API generations to a stable per-caller handle
nirholas1e6f97bf7d93
diff --git a/api/3d/generate.js b/api/3d/generate.jsindex 72e4d7c5a..49655abf2 100644--- a/api/3d/generate.js+++ b/api/3d/generate.js@@ -62,6 +62,28 @@ const UPGRADE = Object.freeze({docs: '/docs/3d-api',});+// Derive a stable, opaque per-caller handle so the free-API lane stops writing+// anonymous rows into the forge_creations flywheel — its highest-growth surface.+// Two sources, in order of durability:+// 1) a caller-supplied stable id (x-forge-client, or x-agent-id for agent+// frameworks) — lets a repeat agent accrue a real, later-claimable body of+// work under one handle, unifying with any direct /api/forge or SDK usage;+// 2) else the caller's own IP, so even fully anonymous traffic segments per+// client instead of collapsing to a single 'anon' bucket.+// The raw value is forwarded only as x-forge-client (see startForge): forge+// salts+sha256s it into client_key, so nothing here reaches the DB in the clear,+// and the real IP never rides x-forwarded-for into forge's own per-IP limiter.+function pickHeader(req, name) {+ const raw = req.headers?.[name];+ const v = Array.isArray(raw) ? raw[0] : raw;+ return typeof v === 'string' ? v.trim() : '';+}+export function agentClientId(req, ip) {+ const supplied = pickHeader(req, 'x-forge-client') || pickHeader(req, 'x-agent-id');+ if (supplied) return supplied.slice(0, 200);+ return ip && ip !== '0.0.0.0' ? `ip:${ip}` : '';+}+// Recommended seconds a polling agent should wait between polls. Derived from the// lane's ETA so a fast draft is polled promptly and a slow job sparingly: a// well-behaved agent that honors this stays under the poll flood-guard@@ -281,6 +303,9 @@ async function generate(req, res) {path: 'image',tier: 'draft',submitTimeoutMs: 240_000,+ // Attribute the durable creation to this caller so the flywheel isn't+ // blind on the free lane (and a repeat agent can later claim its work).+ clientKey: agentClientId(req, ip),});} catch (err) {return failFromLane(res, err);diff --git a/api/_lib/http.js b/api/_lib/http.jsindex 6721a17f3..9f3794775 100644--- a/api/_lib/http.js+++ b/api/_lib/http.js@@ -443,7 +443,7 @@ export function cors(res.setHeader('access-control-allow-methods', methods);res.setHeader('access-control-allow-headers',- 'authorization, content-type, mcp-session-id, mcp-protocol-version, x-payment, payment-signature, idempotency-key, x-irl-device, x-irl-fix, x-forge-client, x-forge-seed',+ 'authorization, content-type, mcp-session-id, mcp-protocol-version, x-payment, payment-signature, idempotency-key, x-irl-device, x-irl-fix, x-forge-client, x-agent-id, x-forge-seed',);// x402: clients (drop-in modal, x402-fetch) must read these to drive the// 402-pay-retry flow and surface settlement receipts. Without `expose`,diff --git a/api/_mcp-studio/forge-client.js b/api/_mcp-studio/forge-client.jsindex ae492e642..24dbbd4f9 100644--- a/api/_mcp-studio/forge-client.js+++ b/api/_mcp-studio/forge-client.js@@ -95,7 +95,14 @@ function internalHeaders() {// whose consumers poll anyway (the public /api/3d/generate) passes a wider// window so a slow-but-working lane returns done instead of burning the GPU// work into a client-side timeout. Interactive surfaces keep the 90s default.-export async function startForge(base, { prompt, imageUrls, aspect, backend, path, tier, internal, submitTimeoutMs }) {+// `clientKey` is a stable, opaque per-caller handle forwarded as the x-forge-client+// header so /api/forge attributes the durable creation (forge_creations row) to the+// real caller instead of collapsing it to the shared 'anon' bucket. It scopes the+// gallery/claim surface to one client without any account. Forge salts+hashes it, so+// the raw value never reaches the DB. Deliberately NOT the caller IP forwarded as+// x-forwarded-for: that would collide with forge's own per-IP free-lane limiter and+// halve the ceiling — identity attribution and rate limiting stay decoupled.+export async function startForge(base, { prompt, imageUrls, aspect, backend, path, tier, internal, submitTimeoutMs, clientKey }) {const submitWindowMs = Number(submitTimeoutMs) > 0 ? Number(submitTimeoutMs) : 90_000;const attempt = async (tierId, withInternal) => {const payload = {@@ -110,7 +117,11 @@ export async function startForge(base, { prompt, imageUrls, aspect, backend, pattry {res = await fetch(`${base}/api/forge`, {method: 'POST',- headers: { 'content-type': 'application/json', ...(withInternal ? internalHeaders() : {}) },+ headers: {+ 'content-type': 'application/json',+ ...(clientKey ? { 'x-forge-client': clientKey } : {}),+ ...(withInternal ? internalHeaders() : {}),+ },body: JSON.stringify(payload),signal: AbortSignal.timeout(submitWindowMs),});