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.

fix(i18n): abort a translate run on a spent balance instead of baking English

nirholas60772369c127
diff --git a/docs/i18n.md b/docs/i18n.md
index 8dc2418d2..ad1fa0aa8 100644
--- a/docs/i18n.md
+++ b/docs/i18n.md
@@ -129,6 +129,21 @@ error is classified separately - it is never retried, never baked, and aborts th
run with the one line that says what to fix. Everything already translated is
kept (the pipeline persists after each chunk) and a re-run resumes.
+A spent balance counts as one of these. HTTP **402** joins 401 and 403 in that
+classifier because a funded key with no credits left answers `402 Insufficient
+credits` to every single call: not a config error, not an auth rejection, and so
+for a while not fatal either. The run treated it as a value the model could not
+render, halved the chunk, halved it again, and baked English onto each lone key.
+It cost 198 Spanish keys before anyone noticed, because the run exited 0. A
+payment wall is a property of the account, never of the string, so splitting and
+retrying cannot change the answer.
+
+When a run does abort on credentials, read the status before assuming the key is
+wrong. `vertex 403: Lightning dunning decision is deny for project` is Google
+billing enforcement against the whole GCP project, so every Vertex model in every
+region returns it and no amount of re-authenticating helps; the fix is on the
+billing account. `402` is the balance. `401` really is the credential.
+
`i18n:backfill` (below) exists to clean up catalogs damaged by this before the
guard existed.
diff --git a/scripts/i18n-translate.mjs b/scripts/i18n-translate.mjs
index 961af5b79..07ad12cb3 100644
--- a/scripts/i18n-translate.mjs
+++ b/scripts/i18n-translate.mjs
@@ -264,15 +264,25 @@ export function configError(message) {
/**
* Should this failure abort the run instead of falling back to English?
*
- * True for anything that means "the credentials are wrong", which fails
- * identically on every key: an absent key or project (configError), and an
- * auth rejection from the provider (401/403). The English fallback exists for
- * the occasional value a model cannot render as valid JSON; applied to a
- * credential failure it silently rewrites a whole catalog into English and
- * exits 0.
+ * True for anything that means "this key will never be served", which fails
+ * identically on every key: an absent key or project (configError), an auth
+ * rejection from the provider (401/403), and an exhausted balance (402). The
+ * English fallback exists for the occasional value a model cannot render as
+ * valid JSON; applied to a whole-account failure it silently rewrites a whole
+ * catalog into English and exits 0.
+ *
+ * 402 is here because leaving it out cost a real catalog. A funded OpenRouter
+ * key with a spent balance answers every request `402 Insufficient credits`,
+ * which is neither a config error nor an auth rejection, so the run treated it
+ * as a per-key rendering failure: halve, retry, halve again, and bake English
+ * on each lone key. 198 Spanish keys were rewritten into English and the run
+ * exited 0. A payment wall is a property of the account, not of the string
+ * being translated, so no amount of retrying or splitting changes the outcome.
*/
export function isFatalAuthFailure(err) {
- return Boolean(err?.isConfigError || err?.status === 401 || err?.status === 403);
+ return Boolean(
+ err?.isConfigError || err?.status === 401 || err?.status === 402 || err?.status === 403,
+ );
}
function modelName() {
diff --git a/tests/i18n-markup.test.js b/tests/i18n-markup.test.js
index 416b47c15..072b9dec9 100644
--- a/tests/i18n-markup.test.js
+++ b/tests/i18n-markup.test.js
@@ -139,6 +139,18 @@ describe('isFatalAuthFailure', () => {
expect(isFatalAuthFailure(Object.assign(new Error('vertex 403'), { status: 403 }))).toBe(true);
});
+ // Regression: a spent OpenRouter balance answers every call `402 Insufficient
+ // credits`. Classified as retryable, that walked the halve-and-retry path down
+ // to single keys and baked English into 198 of them, exiting 0. A payment wall
+ // belongs to the account, not to the string, so splitting can never help.
+ it('is fatal on a 402, which is a spent balance and not a bad string', () => {
+ expect(
+ isFatalAuthFailure(
+ Object.assign(new Error('openrouter 402: Insufficient credits'), { status: 402 }),
+ ),
+ ).toBe(true);
+ });
+
it('is NOT fatal on a rate limit, which retry and backoff do handle', () => {
expect(isFatalAuthFailure(Object.assign(new Error('429'), { status: 429 }))).toBe(false);
});