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
docs(forge): correct the SDK reference against what forge actually returns
nirholas9ab18bc38e3b
diff --git a/packages/forge/README.md b/packages/forge/README.mdindex bd0100a96..8460e2d3e 100644--- a/packages/forge/README.md+++ b/packages/forge/README.md@@ -31,7 +31,7 @@> auth-free `/api/forge` endpoint: a free [TRELLIS](https://github.com/microsoft/TRELLIS)> lane on NVIDIA NIM, paid high-detail tiers billed in USDC over> [x402](https://x402.org), and bring-your-own-key geometry backends-> (Meshy, Tripo). It pairs with [`@three-ws/avatar`](https://www.npmjs.com/package/@three-ws/avatar)+> (Meshy, Tripo, Rodin). It pairs with [`@three-ws/avatar`](https://www.npmjs.com/package/@three-ws/avatar)> — Forge *makes* the model, `@three-ws/avatar` *renders* it.## Why@@ -51,8 +51,8 @@ pipeline, done once:- **Rig-ready.** One flag chains generation into auto-rigging, so the outputdrops straight into the three.ws animation runtime — idle, walk, emotes.-This is the SDK twin of the [3D Studio MCP server](https://three.ws/mcp) — the-same engine, exposed as plain functions instead of MCP tools.+This is the SDK twin of the [3D Studio MCP server](https://three.ws/docs/mcp-3d-studio),+the same engine, exposed as plain functions instead of MCP tools.## Install@@ -70,12 +70,16 @@ The free lane needs no key:```jsimport { forge } from '@three-ws/forge';-const model = await forge('a chrome robot with neon trim');+const model = await forge('a chrome robot with neon trim', { tier: 'draft' });-console.log(model.glbUrl); // → https://three.ws/cdn/forge/….glb (durable)-console.log(model.viewerUrl); // → https://three.ws/forge?share=…+console.log(model.glbUrl); // → durable https://…/forge/….glb+console.log(model.backend); // → which engine actually produced it```+`glbUrl` is a durable CDN URL you can hand straight to a viewer. `viewerUrl` is+the shareable three.ws link, and it is `null` unless the API attached a creation+id (the anonymous free lane usually does not).+A fuller run — high tier, geometry-first, then auto-rig:```js@@ -120,11 +124,14 @@ or an input object.| Option | Type | Default | Notes ||---|---|---|---|-| `path` | `'image' \| 'geometry' \| 'sketch'` | `'image'` | How geometry is produced — see [How it works](#how-it-works). |+| `path` | `'image' \| 'geometry' \| 'sketch'` | `'image'` | How geometry is produced, see [How it works](#how-it-works). || `tier` | `'draft' \| 'standard' \| 'high'` | `'standard'` | Polygon budget + texture richness. |-| `backend` | `string` | auto | Force a generation backend (`nvidia`, `huggingface`, `meshy`, `tripo`). |-| `providerKey` | `string` | — | BYOK key for the `geometry` path (Meshy/Tripo). |-| `payWith` | `'x402' \| 'credits'` | `'x402'` | Billing lane for paid tiers (see [Pricing](#pricing)). |+| `backend` | `string` | auto | Force a generation backend. Read the live ids from `catalog()`. |+| `providerKey` | `string` | — | BYOK key for the `geometry` path (Meshy/Tripo/Rodin). Overrides the client-level key, and is resent on every poll. |+| `payWith` | `'credits' \| 'x402'` | `'credits'` | Billing lane, see [Pricing](#pricing). `'x402'` switches endpoints. |+| `pollIntervalMs` | `number` | `2500` | Gap between job polls. |+| `timeoutMs` | `number` | `180000` | Give up on a job that never finishes. |+| `headers` | `object` | — | Extra headers merged into every request for this call. || `signal` | `AbortSignal` | — | Cancel an in-flight generation. || `onProgress` | `(job) => void` | — | Called on each poll tick with the latest job state. |@@ -133,15 +140,20 @@ or an input object.| Field | Type | Notes ||---|---|---|| `glbUrl` | `string` | Durable hosted GLB URL. |-| `viewerUrl` | `string` | Shareable three.ws viewer link. |+| `viewerUrl` | `string \| null` | Shareable three.ws viewer link. `null` when the response carried no creation id. || `jobId` | `string \| null` | `null` when the backend returned synchronously. |+| `creationId` | `string \| null` | Gallery/creation id, when the lane records one. || `status` | `'done'` | Resolved jobs are always `done`; failures throw. |-| `path` / `tier` / `backend` | `string` | What actually produced the mesh. |-| `etaSeconds` | `number` | Backend ETA at submit time. |+| `path` / `tier` / `backend` | `string \| null` | What actually produced the mesh. |+| `etaSeconds` | `number \| null` | Backend ETA at submit time. |+| `estimatedCredits` | `number \| null` | BYOK vendor spend estimate, where the backend reports one. |+| `durable` | `boolean` | `true` once the GLB has been copied to three.ws storage. |+| `raw` | `object` | The untouched API response, for anything not mapped above. |`forge()` submits to `POST /api/forge`, then polls `GET /api/forge?job=<id>`until the job is `done` (the free NVIDIA lane often returns synchronously, with-no polling). Failures reject with a typed [`ForgeError`](#errors--edge-cases).+no polling). Failures reject with a typed+[`ThreeWsError`](#errors--edge-cases).### `rig(glbUrl, options?) → Promise<ForgeResult>`@@ -151,10 +163,56 @@ with a rigged `glbUrl`.### `catalog() → Promise<Catalog>`-Fetch the live tier / backend / cost matrix (`GET /api/forge?catalog`) — the+Fetch the live tier / backend / cost matrix (`GET /api/forge?catalog=1`), thesingle source of truth for prices, ETAs, which backends are configured, andwhich paths each serves. Use it to render a picker before the user commits.+### `getJob(jobId, options?) → Promise<ForgeResult>`++Read one job's current state without waiting for it to finish, so you can drive+your own progress UI, resume after a restart, or poll from a different process+than the one that submitted. Wraps `GET /api/forge?job=<id>` and returns the+same shape `forge()` resolves to, at whatever status the job is in right now.+Pass `providerKey` if the job was submitted with a BYOK key: the API re-resolves+the key on every poll and cannot report on the job without it.++```js+const job = await getJob('job_abc', { providerKey: process.env.MESHY_KEY });+console.log(job.status); // 'queued' | 'running' | 'done' | 'failed'+```++### `createForge(clientOptions?) → ForgeClient`++Bind a base URL, `fetch`, and credentials once and reuse them. The bare+`forge` / `rig` / `catalog` / `getJob` exports are a shared default client with+no options; reach for `createForge` when you need any of these:++| Client option | Type | Notes |+|---|---|---|+| `baseUrl` | `string` | API origin. Defaults to `THREE_WS_BASE_URL`, then `https://three.ws`. |+| `fetch` | `typeof fetch` | Bring your own, e.g. a payment-aware fetch that settles 402s. |+| `apiKey` | `string` | Sent as `Authorization: Bearer …`, for the credits lane. |+| `providerKey` | `string` | Default BYOK key. A per-call `providerKey` wins. |+| `headers` | `object` | Default headers on every request. |++It returns `{ forge, rig, catalog, getJob }` with identical signatures:++```js+import { createForge } from '@three-ws/forge';+import { x402Client } from '@x402/core/client';+import { ExactSvmScheme } from '@x402/svm/exact/client';+import { wrapFetchWithPayment } from '@x402/fetch';+import { createKeyPairSignerFromBytes } from '@solana/kit';+import bs58 from 'bs58';++const signer = await createKeyPairSignerFromBytes(bs58.decode(process.env.SOLANA_SECRET_KEY));+const payer = new x402Client();+payer.register('solana:*', new ExactSvmScheme(signer));++const client = createForge({ fetch: wrapFetchWithPayment(globalThis.fetch, payer) });+const paid = await client.forge('a marble bust', { tier: 'high', payWith: 'x402' });+```+## How it worksTwo orthogonal axes describe every request — `path` (how geometry is produced)@@ -166,7 +224,7 @@ prompt / image / sketch▼┌──────────┐ image ┌───────────────────────────────┐│ path = ├────────────▶ FLUX/Imagen → TRELLIS·Hunyuan3D │ fast default, free lane- │ ├─ geometry ─▶ Meshy / Tripo native text→mesh │ BYOK, higher detail ceiling+ │ ├─ geometry ─▶ Meshy/Tripo/Rodin native text→mesh│ BYOK, higher detail ceiling│ ├─ sketch ───▶ TripoSG-scribble │ drawing + name → raw geometry└──────────┘ └───────────────┬───────────────┘▼@@ -179,7 +237,7 @@ prompt / image / sketch- **`image`** (default) — text is painted into a reference image, thenreconstructed to a mesh. Fast, and the free lane lives here.- **`geometry`** — a native 3D model emits mesh geometry directly, so detail- isn't capped by a single synthesized view. Bring your own Meshy/Tripo key.+ isn't capped by a single synthesized view. Bring your own Meshy, Tripo, or Rodin key.- **`sketch`** — a drawing plus a prompt naming it drives TripoSG-scribble toraw geometry (no textures).@@ -189,38 +247,74 @@ fabricates a model.## Pricing-The free lane is genuinely free. Paid tiers are flat per-call prices, quoted in-USDC (6-decimal atomics) and settled over [x402](https://x402.org) or from a-prepaid credit balance:+The browser-facing lane on `/api/forge` is free where the free engines can serve+the request, and asks for an account (credits) where they cannot. There is also+a pay-per-call twin at `POST /api/x402/forge` for agents with a wallet and no+account: one USDC payment, one generation, no signup. `payWith` picks between+them.-| Tier | Polygons (target) | PBR | Price | Lane |-|---|---|---|---|---|-| **draft** | ~12k | — | **free** on NVIDIA NIM (text) | TRELLIS |-| **standard** | ~30k | — | **$0.15** (free on the NIM text lane) | TRELLIS / paid |-| **high** | ~200k | yes | **$0.50** | paid |+| Tier | Polygons (target) | PBR | Pay-per-call price |+|---|---|---|---|+| **draft** | ~12k | no | **$0.05** |+| **standard** | ~30k | no | **$0.15** |+| **high** | ~200k | yes | **$0.50** |-Set `payWith: 'x402'` (default) to pay per call with USDC, or `payWith:-'credits'` to draw from a signed-in prepaid balance. Pair with-[`@three-ws/x402-fetch`](https://www.npmjs.com/package/@three-ws/x402-fetch) to-automate the 402 settlement. Prices are authoritative in `catalog()` — read-them at runtime rather than hardcoding.+Prices are flat per call, quoted in USDC (6-decimal atomics) and settled on+Solana. They are authoritative in `catalog()`, so read them at runtime rather+than hardcoding.++```js+// Pay-per-call: no account, no key, just a wallet.+const model = await forge('a marble bust', { tier: 'high', payWith: 'x402' });+```++Because the x402 endpoint picks its own generation lane, it does not accept+`path`, `backend`, or `providerKey`; passing one throws `invalid_input` before+any request is sent. Without a payment-aware `fetch` the first call rejects with+`PaymentRequiredError`, whose `accepts` carries the challenge (asset, amount,+network, payTo) so you can settle it yourself. The live route quotes **Solana+USDC**, so the payment-aware fetch shown under+[`createForge`](#createforgeclientoptions--forgeclient) is the one to reach for.+Once paid, the job token is polled for free on the shared+`GET /api/forge?job=<id>` endpoint, which is what this SDK does for you.## Errors & edge cases-`forge()` and `rig()` reject with a typed `ForgeError` carrying a `code`:+`forge()`, `rig()`, and `getJob()` reject with a typed `ThreeWsError` carrying a+`code`, an HTTP `status`, and the parsed `body`. HTTP 402 rejects with the+`PaymentRequiredError` subclass, which adds `accepts`. Both are exported.| `code` | HTTP | Meaning | Recovery ||---|---|---|---|-| `needs_key` | 501 | The `geometry` path needs a BYOK Meshy/Tripo key. | Pass `providerKey`. |-| `backend_unavailable` | 503 | The selected backend isn't configured. | Omit `backend` to auto-route, or pick another. |-| `payment_required` | 402 | Paid tier with no payment. | Provide an x402 payer or top up credits. |-| `insufficient_credits` | 402 | `payWith: 'credits'` balance too low. | Top up at `/credits`. |-| `unauthorized` | 401 | Credit lane needs a signed-in account. | Authenticate, or use `payWith: 'x402'`. |-| `rate_limited` | 429 | Too many submissions. | Honour `retryAfter` on the error. |+| `invalid_input` | — | Rejected client-side before any request: unknown `tier`/`path`/`payWith`, no prompt and no image, or an x402 call carrying `path`/`backend`/`providerKey`. | Fix the call. |+| `needs_key` | 501 | The selected BYOK backend needs your own provider key. | Pass `providerKey`. |+| `backend_unconfigured` | 501 | That backend has no credential on the server. | Omit `backend` to auto-route, or pick another. |+| `unconfigured` | 503 | No generation backend is configured at all. | Retry later, or self-host. |+| `generation_unavailable` | 503 | Every eligible backend failed or is down. | Retry, or change `path`/`tier`. |+| `payment_required` | 402 | The x402 lane wants payment. `accepts` carries the challenge. | Settle it, or use a payment-aware `fetch`. |+| `three_hold_required` | 402 | The paid gate wants a $THREE hold or a per-use payment. | Hold $THREE, or pay the quoted amount. |+| `insufficient_credits` | 402 | The account's credit balance is too low. | Top up, or use `payWith: 'x402'`. |+| `unauthorized` | 401 | The credits lane needs a signed-in account. | Authenticate, or use `payWith: 'x402'`. |+| `rate_limited` | 429 | Too many submissions from this IP. | Honour `retryAfter` on the error. |+| `timeout` | — | The job did not finish within `timeoutMs`. | Raise `timeoutMs`, or resume with `getJob(jobId)`. |+| `network_error` | — | The request never reached the API. | Check connectivity / `baseUrl`. || `generation_failed` | — | The backend produced no usable mesh. | Retry, or change `path`/`backend`. |Every state is designed: a missing key returns `needs_key` (not a crash), an-unconfigured backend returns `503` (not a fake model). Mirror that in your UI.+unconfigured backend returns a `501`/`503` state (not a fake model). Mirror that+in your UI.++```js+import { forge, ThreeWsError, PaymentRequiredError } from '@three-ws/forge';++try {+ await forge('a marble bust', { tier: 'high', payWith: 'x402' });+} catch (err) {+ if (err instanceof PaymentRequiredError) console.log(err.accepts);+ else if (err instanceof ThreeWsError) console.log(err.code, err.status);+ else throw err;+}+```## Examples@@ -257,7 +351,7 @@ const rigged = await rig(base.glbUrl);- [`@three-ws/avatar`](https://www.npmjs.com/package/@three-ws/avatar) — render and animate the GLB Forge produces.- [`@three-ws/walk`](https://www.npmjs.com/package/@three-ws/walk) — a rigged Forge model as a page companion.-- [`@three-ws/x402-fetch`](https://www.npmjs.com/package/@three-ws/x402-fetch) — auto-pay the paid tiers.+- [`@three-ws/x402-mcp`](https://www.npmjs.com/package/@three-ws/x402-mcp) — pay any x402 endpoint from a Solana keypair.- [`@three-ws/avatar-schema`](https://www.npmjs.com/package/@three-ws/avatar-schema) — validate on-chain avatar manifests.---