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(avatars): let a long-running lane refuse a plan limit before it spends GPU time

nirholas1ebbf77bab0b
diff --git a/api/_lib/avatars.js b/api/_lib/avatars.js
index ff52013fa..823534928 100644
--- a/api/_lib/avatars.js
+++ b/api/_lib/avatars.js
@@ -489,6 +489,31 @@ export async function enforceQuotas(userId, incomingBytes) {
}
}
+/**
+ * Is this error one of enforceQuotas' plan-limit refusals? Long-running lanes
+ * (reconstruct, auto-rig) only reach createAvatar minutes after the user
+ * pressed the button, so they need to tell a plan refusal apart from an engine
+ * fault: the first is the caller's to fix, the second is ours.
+ * @param {unknown} err
+ * @returns {boolean}
+ */
+export function isPlanLimitError(err) {
+ const code = /** @type {any} */ (err)?.code;
+ return typeof code === 'string' && code.startsWith('plan_limit');
+}
+
+/**
+ * Pre-flight the quotas that a not-yet-generated avatar can already be judged
+ * against: the per-plan avatar count, and whether the library is already at its
+ * total-bytes ceiling. Lets a lane that will spend real GPU time refuse in
+ * milliseconds instead of failing at materialization, after the spend.
+ * Per-file size still has to wait for the finished mesh.
+ * @param {string} userId
+ */
+export async function assertAvatarSlotAvailable(userId) {
+ await enforceQuotas(userId, 0);
+}
+
// ── helpers ──────────────────────────────────────────────────────────────────
function decorate(row) {
const bakedFresh = isBakedFresh(row);