Skip to content

The open source AI video agent: turns any coding agent into a video agent, with an editor to change anything it makes.

Providers: ElevenLabs' "paid plan required" is not "not enough balance" (#205)

WEBGRS10eacd784dde
diff --git a/.changeset/elevenlabs-paid-plan.md b/.changeset/elevenlabs-paid-plan.md
new file mode 100644
index 0000000..01ea75b
--- /dev/null
+++ b/.changeset/elevenlabs-paid-plan.md
@@ -0,0 +1,5 @@
+---
+"openfilm": patch
+---
+
+Media services: an account whose plan doesn't include what was asked (ElevenLabs' free plan, for music or a voice from its library) is told so, with the service's own reason, instead of "doesn't have enough balance", which sent people with credits left to top up, or "did not accept your key", which sent them to check a key that works.
diff --git a/packages/openfilm/studio/server/providers/common.mjs b/packages/openfilm/studio/server/providers/common.mjs
index 0b8185c..d1bca1b 100644
--- a/packages/openfilm/studio/server/providers/common.mjs
+++ b/packages/openfilm/studio/server/providers/common.mjs
@@ -26,18 +26,28 @@ export async function call(service, url, init, ctx) {
if (res.ok) return res;
const text = await res.text().catch(() => '');
if (outOfBalance(res.status, text)) throw noBalance(service);
- if (res.status === 401 || res.status === 403) throw new Error(`${service} did not accept your key (${res.status}). Check it in Studio: Settings (the OpenFilm logo at the top left) → Providers.`);
const reason = reasonOf(text).split(ctx.key).join('•••').slice(0, 500);
+ if (PAID_PLAN.test(text)) throw new Error(`${service} needs a paid plan for this (${res.status})${reason ? `: ${reason}` : ''}`);
+ if (res.status === 401 || res.status === 403) throw new Error(`${service} did not accept your key (${res.status}). Check it in Studio: Settings (the OpenFilm logo at the top left) → Providers.`);
throw new Error(`${service} answered ${res.status}${reason ? `: ${reason}` : ''}`);
}
/**
- * Whether a service's error says its account has no balance left for this, as each says it: 402 Payment Required;
- * Tavily's 432 and 433; OpenAI's `insufficient_quota` (a 429); ElevenLabs' `quota_exceeded` (a 401); fal's "Exhausted balance" (a 403, the
- * account locked until it is topped up); Gemini's depleted prepayment credits (a 429). A plain rate limit is not one.
+ * What the account's plan does not include, balance or not: ElevenLabs' free plan and its music, or a voice from its
+ * library. Its documented codes are `subscription_required` and `feature_not_available` (403s); `paid_plan_required`
+ * comes as a 402.
+ */
+const PAID_PLAN = /paid_plan_required|subscription_required|feature_not_available/i;
+
+/**
+ * Whether a service's error says its account has no balance left for this, as each says it: 402 Payment Required
+ * (but a plan that does not include it); Tavily's 432 and 433; OpenAI's `insufficient_quota` (a 429); ElevenLabs'
+ * `quota_exceeded` (a 401); fal's "Exhausted balance" (a 403, the account locked until it is topped up); Gemini's
+ * depleted prepayment credits (a 429). A plain rate limit is not one.
* @param {number} status @param {string} text the error's body
*/
export function outOfBalance(status, text) {
+ if (PAID_PLAN.test(text)) return false;
if (status === 402) return true;
/* Tavily's plan and pay-as-you-go limits */
if (status === 432 || status === 433) return true;
diff --git a/packages/openfilm/studio/server/providers/common.test.mjs b/packages/openfilm/studio/server/providers/common.test.mjs
index 85172b9..1f36454 100644
--- a/packages/openfilm/studio/server/providers/common.test.mjs
+++ b/packages/openfilm/studio/server/providers/common.test.mjs
@@ -79,11 +79,20 @@ test('no balance, as each service says it, is one error for all; a plain rate li
assert.ok(!outOfBalance(429, JSON.stringify({ error: { message: 'Rate limit reached for requests', type: 'requests', code: 'rate_limit_exceeded' } })));
assert.ok(!outOfBalance(429, JSON.stringify({ error: { code: 429, message: 'Resource has been exhausted (e.g. check quota).', status: 'RESOURCE_EXHAUSTED' } })));
assert.ok(!outOfBalance(401, JSON.stringify({ error: { message: 'Incorrect API key provided' } })));
+ /* ElevenLabs' free plan: music, or a voice from its library, is a 402 whatever the credits left */
+ const freePlan = { detail: { status: 'paid_plan_required', message: 'Free users cannot use library voices via the API. Please upgrade your subscription to use this voice.' } };
+ assert.ok(!outOfBalance(402, JSON.stringify(freePlan)));
+ /* and its documented plan errors, both 403s */
+ const subscription = { detail: { type: 'authorization_error', code: 'subscription_required', message: 'A paid subscription is required to access this feature.' } };
+ const feature = { detail: { type: 'authorization_error', code: 'feature_not_available', message: 'This feature is not available on your current plan.' } };
+ assert.ok(!outOfBalance(403, JSON.stringify(subscription)));
+ assert.ok(!outOfBalance(403, JSON.stringify(feature)));
const ctx = { key: 'sk-test', signal: new AbortController().signal };
const { createServer } = await import('node:http');
const server = createServer((req, res) => {
- const [status, body] = req.url === '/quota' ? [429, { error: { type: 'insufficient_quota' } }] : [401, { error: { message: 'bad key sk-test' } }];
+ const answers = { '/quota': [429, { error: { type: 'insufficient_quota' } }], '/plan': [402, freePlan], '/subscription': [403, subscription], '/feature': [403, feature] };
+ const [status, body] = answers[/** @type {keyof typeof answers} */ (req.url)] ?? [401, { error: { message: 'bad key sk-test' } }];
res.writeHead(status, { 'content-type': 'application/json' }).end(JSON.stringify(body));
});
await new Promise((done) => server.listen(0, '127.0.0.1', done));
@@ -91,6 +100,12 @@ test('no balance, as each service says it, is one error for all; a plain rate li
try {
await assert.rejects(call('OpenAI', `${at}/quota`, {}, ctx), (e) => e.code === 'balance' && e.message === "OpenAI doesn't have enough balance for this.");
await assert.rejects(call('OpenAI', `${at}/key`, {}, ctx), (e) => e.code === undefined && /did not accept your key/.test(e.message));
+ await assert.rejects(call('ElevenLabs', `${at}/plan`, {}, ctx), (e) => e.code === undefined
+ && e.message === 'ElevenLabs needs a paid plan for this (402): Free users cannot use library voices via the API. Please upgrade your subscription to use this voice.');
+ await assert.rejects(call('ElevenLabs', `${at}/subscription`, {}, ctx), (e) => e.code === undefined
+ && e.message === 'ElevenLabs needs a paid plan for this (403): A paid subscription is required to access this feature.');
+ await assert.rejects(call('ElevenLabs', `${at}/feature`, {}, ctx), (e) => e.code === undefined
+ && e.message === 'ElevenLabs needs a paid plan for this (403): This feature is not available on your current plan.');
} finally {
server.close();
}