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(tts): blame the caller for a 400 or 404 from ElevenLabs instead of the gateway

nirholas1bb8ef4f58ac
diff --git a/api/_lib/voice-providers.js b/api/_lib/voice-providers.js
index 1edabbcc7..454a9cce4 100644
--- a/api/_lib/voice-providers.js
+++ b/api/_lib/voice-providers.js
@@ -474,9 +474,17 @@ export async function synthesizeVoice(opts) {
}
if (!resp.ok) {
const detail = await resp.text().catch(() => '');
+ // 400/404 here is the caller's voiceId, not our lane: the model is
+ // validated above and the key is checked separately, so the only
+ // caller-controlled input left is the voice. Reporting it as
+ // invalid_argument lets the handler answer 4xx instead of blaming
+ // itself with a 502.
throw tagged(
`ElevenLabs returned ${resp.status}: ${detail.slice(0, 300)}`,
- resp.status === 429 ? 'rate_limited' : resp.status === 401 ? 'invalid_key' : 'provider_error',
+ resp.status === 429 ? 'rate_limited'
+ : resp.status === 401 ? 'invalid_key'
+ : resp.status === 400 || resp.status === 404 ? 'invalid_argument'
+ : 'provider_error',
);
}
return {
diff --git a/api/tts/eleven.js b/api/tts/eleven.js
index e3c730b2b..f52751fac 100644
--- a/api/tts/eleven.js
+++ b/api/tts/eleven.js
@@ -253,7 +253,20 @@ export default wrap(async (req, res) => {
const msg = await elResp.text().catch(() => '');
console.error('[tts/eleven] ElevenLabs error', elResp.status, msg);
await refundMetering();
- return error(res, 502, 'upstream_error', `ElevenLabs returned ${elResp.status}`);
+ // A 400/404 from the text-to-speech endpoint is the caller's voiceId: the
+ // model id and the key are resolved server-side, so the voice is the only
+ // caller-controlled part of the request left. Answering 502 blamed the
+ // platform for a typo the caller can fix, and hid it from the client's own
+ // error handling. The charge is already refunded above either way.
+ const callerFault = elResp.status === 400 || elResp.status === 404;
+ return error(
+ res,
+ callerFault ? 400 : 502,
+ callerFault ? 'validation_error' : 'upstream_error',
+ callerFault
+ ? `ElevenLabs does not have voice "${voiceId}" on this account`
+ : `ElevenLabs returned ${elResp.status}`,
+ );
}
// Stream the clip to the client for low TTFB while teeing the chunks into a