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.

docs(forge): document the self-hosted NIM URL split and cover receipt asset decimals

nirholas75f473a3cf42
diff --git a/docs/tutorials/nvidia-nim-self-host.md b/docs/tutorials/nvidia-nim-self-host.md
index 5db4e90cd..cbec69aad 100644
--- a/docs/tutorials/nvidia-nim-self-host.md
+++ b/docs/tutorials/nvidia-nim-self-host.md
@@ -50,17 +50,21 @@ Set two environment variables on your three.ws deployment. Production runs on Go
| Variable | What it is |
|----------|-----------|
-| `MODEL_TRELLIS_URL` | The public https origin of your NIM, e.g. `https://trellis.yourdomain.com` |
-| `NVIDIA_API_KEY` | Bearer token forwarded to the NIM (if your gateway requires auth) |
+| `NIM_TRELLIS_URL` | The public https origin of your NIM, e.g. `https://trellis.yourdomain.com` |
+| `NIM_TRELLIS_KEY` | Bearer token forwarded to the NIM (if your gateway requires auth). `NVIDIA_API_KEY` is accepted as a fallback |
```bash
gcloud run services update three-ws-api --region us-central1 \
- --update-env-vars MODEL_TRELLIS_URL=https://trellis.yourdomain.com
+ --update-env-vars NIM_TRELLIS_URL=https://trellis.yourdomain.com
gcloud run services update three-ws-api --region us-central1 \
- --update-env-vars NVIDIA_API_KEY=your-ngc-token
+ --update-env-vars NIM_TRELLIS_KEY=your-ngc-token
```
+`--update-env-vars` merges into the existing set. Never use `--set-env-vars` for a single key: it replaces the service's entire environment.
+
+`NIM_TRELLIS_URL` is deliberately separate from `MODEL_TRELLIS_URL`. The latter points at the platform's own Cloud Run TRELLIS worker, which speaks an async `/infer` plus `/tasks/{id}` API rather than the NIM's synchronous `/v1/infer`, so the two are never interchangeable.
+
Confirm three.ws can see it:
```bash
@@ -156,10 +160,11 @@ The proxy normalizes every documented artifact shape (inline `base64`, a bare st
| Symptom | Cause & fix |
|---------|-------------|
-| `configured: false` from health | `MODEL_TRELLIS_URL` isn't set on the deployment |
-| `reachable: false` | The NIM's `/v1/health/ready` didn't answer — check the container and your TLS front |
+| `configured: false` from health | `NIM_TRELLIS_URL` isn't set on the deployment |
+| `reachable: false` | The NIM's `/v1/health/ready` didn't answer. Check the container and your TLS front |
| `nim_timeout` (504) | Cold `large:image` start; retry once the GPU is warm |
-| `nim_auth` (502) | The NIM rejected the bearer — check `NVIDIA_API_KEY` or your gateway auth |
+| `nim_auth` (502) | The NIM rejected the bearer. Check `NIM_TRELLIS_KEY` (or `NVIDIA_API_KEY`) or your gateway auth |
+| `nim_error` (502) with a 404 body | The base URL isn't serving the NIM contract. A plain `/infer` API is not a NIM: the container must answer `POST /v1/infer` |
| `bad_base_url` (400) | An override `baseUrl` was http, an IP literal, or a private/`.internal` host |
---
diff --git a/pages/forge-nim.html b/pages/forge-nim.html
index fe2181886..7e29a0d53 100644
--- a/pages/forge-nim.html
+++ b/pages/forge-nim.html
@@ -601,7 +601,7 @@
<input
type="url"
id="base-url"
- placeholder="https://your-nim-host (defaults to MODEL_TRELLIS_URL)"
+ placeholder="https://your-nim-host (defaults to NIM_TRELLIS_URL)"
spellcheck="false"
autocapitalize="off"
/>
diff --git a/tests/x402-my-receipts-asset-decimals.test.js b/tests/x402-my-receipts-asset-decimals.test.js
new file mode 100644
index 000000000..b8a2494f5
--- /dev/null
+++ b/tests/x402-my-receipts-asset-decimals.test.js
@@ -0,0 +1,63 @@
+/**
+ * /api/x402/my-receipts: the amount scale it hands a buyer.
+ *
+ * A receipt records the settlement `asset` verbatim, so the buyer's client has
+ * an atomic amount and an asset address and nothing that says how to divide
+ * one by the other. The endpoint resolves that scale server-side from the same
+ * env config that builds the 402 accepts, and returns null for anything it does
+ * not recognise, at which point the client renders raw atomic units: a $0.001
+ * payment reads as "1000".
+ *
+ * That makes the mapping a coverage problem, not a lookup problem. It shipped
+ * covering USDC on Solana, Base, and BSC while the accepts list had grown two
+ * more assets (USD₮0 on X Layer, $THREE on the Solana rail), so receipts from
+ * either rail came back unscaled. This test derives the expectation from
+ * buildExactRequirements rather than restating a list, so the next asset added
+ * to an accept fails here instead of silently reaching buyers unscaled.
+ */
+
+import { describe, it, expect, beforeAll } from 'vitest';
+
+// Receiver + fee-payer addresses gate which accepts are advertised at all.
+// Synthetic values: nothing here verifies or settles a payment.
+beforeAll(() => {
+ process.env.X402_PAY_TO_SOLANA ||= 'THREEsyntheticReceiver11111111111111111111111';
+ process.env.X402_FEE_PAYER_SOLANA ||= 'THREEsyntheticFeePayer111111111111111111111111';
+ process.env.X402_RING_SELF_PAY ||= 'true';
+ process.env.X402_PAY_TO_BASE ||= '0x1111111111111111111111111111111111111111';
+ process.env.X402_PAY_TO_BSC ||= '0x2222222222222222222222222222222222222222';
+ process.env.X402_PAY_TO_XLAYER ||= '0x3333333333333333333333333333333333333333';
+});
+
+const { assetDecimals } = await import('../api/x402/my-receipts.js');
+const { buildExactRequirements } = await import('../api/_lib/x402-spec.js');
+const { env } = await import('../api/_lib/env.js');
+
+describe('assetDecimals covers every advertised settlement asset', () => {
+ it('resolves a scale for each asset in the live 402 accepts', () => {
+ const accepts = buildExactRequirements('https://three.ws/api/x402/notify');
+ expect(accepts.length).toBeGreaterThan(0);
+
+ const unscaled = accepts
+ .map((a) => a.asset)
+ .filter(Boolean)
+ .filter((asset) => assetDecimals(asset) == null);
+
+ expect(unscaled).toEqual([]);
+ });
+
+ it('scales $THREE by its own decimals, not a hardcoded 6', () => {
+ expect(assetDecimals(env.THREE_TOKEN_MINT)).toBe(env.THREE_TOKEN_DECIMALS);
+ });
+
+ it('matches an asset address case-insensitively (EVM checksums vary)', () => {
+ expect(assetDecimals(env.X402_ASSET_ADDRESS_BASE.toUpperCase())).toBe(6);
+ expect(assetDecimals(env.X402_ASSET_ADDRESS_XLAYER.toLowerCase())).toBe(6);
+ });
+
+ it('returns null for an asset this deployment never pays in', () => {
+ expect(assetDecimals('THREEsyntheticUnknownAsset11111111111111111')).toBeNull();
+ expect(assetDecimals('')).toBeNull();
+ expect(assetDecimals(null)).toBeNull();
+ });
+});