Skip to content

Generate clean 2D game sprites & animation atlases — component-row pipeline: state rows, alpha cleanup, frame extraction, runtime atlases. Codex/Claude skill.

refactor(audio): the two ElevenLabs 429 codes that are sent again written once as gen.retry.ELEVENLABS_BUSY, which again_after reads and audio.provider's SAFE_CODES takes in

Soohong Kim0241bae26aea
diff --git a/sprite_gen/audio/provider.py b/sprite_gen/audio/provider.py
index 5846358..a61e425 100644
--- a/sprite_gen/audio/provider.py
+++ b/sprite_gen/audio/provider.py
@@ -14,7 +14,7 @@ from sprite_gen.gen.xai import error_body, NO_ANSWER
AUTH_ENV = 'ELEVENLABS_API_KEY'
FORMAT = 'mp3_44100_128'
-SAFE_CODES = frozenset({'system_busy', 'too_many_concurrent_requests', 'quota_exceeded',
+SAFE_CODES = frozenset({*retry.ELEVENLABS_BUSY, 'quota_exceeded',
'invalid_api_key', 'missing_permissions', 'bad_prompt', 'bad_composition_plan',
'content_policy_violation', 'unauthorized', 'invalid_request'})
diff --git a/sprite_gen/gen/retry.py b/sprite_gen/gen/retry.py
index 6c728cb..6504544 100644
--- a/sprite_gen/gen/retry.py
+++ b/sprite_gen/gen/retry.py
@@ -77,6 +77,9 @@ ACT_FIRST: dict[str, frozenset[str]] = {
address.XAI: frozenset(),
address.ELEVENLABS: frozenset(),
}
+# ElevenLabs documents only these two 429 codes as requests it could not process.
+# https://elevenlabs.io/docs/help-center/technical/api-error-code-429 (2026-10-13).
+ELEVENLABS_BUSY = ("system_busy", "too_many_concurrent_requests")
GET_AGAIN = frozenset({429, 500, 502, 503, 504, 529})
Sleep = Callable[[float], None]
@@ -110,11 +113,9 @@ def _act_first(provider: str, body: Any) -> bool:
def again_after(provider: str, method: str, status: int, body: Any, headers: Any, failures: int) -> float | None:
"""Seconds to wait before sending the request again after its `failures`-th failed answer in a row,
or None when it is not sent again (the rule in the module docstring)."""
- # ElevenLabs documents only these two 429 codes as requests it could not process.
- # https://elevenlabs.io/docs/help-center/technical/api-error-code-429 (2026-10-13).
if provider == address.ELEVENLABS and method != "GET":
detail = body.get("detail") if isinstance(body, dict) else None
- if not isinstance(detail, dict) or detail.get("status") not in ("system_busy", "too_many_concurrent_requests"):
+ if not isinstance(detail, dict) or detail.get("status") not in ELEVENLABS_BUSY:
return None
if failures > ASKS_AGAIN:
return None
diff --git a/tests/audio/test_sound.py b/tests/audio/test_sound.py
index 0479d05..33a526c 100644
--- a/tests/audio/test_sound.py
+++ b/tests/audio/test_sound.py
@@ -242,6 +242,13 @@ def test_unproven_refusals_are_not_retried(status, body):
assert retry.again_after('elevenlabs', 'POST', status, body, {}, 1) is None
[email protected]('code', ['system_busy', 'too_many_concurrent_requests'])
+def test_the_two_documented_busy_codes_are_retried_and_named(code):
+ body = {'detail': {'status': code}}
+ assert retry.again_after('elevenlabs', 'POST', 429, body, {}, 1) is not None
+ assert provider._code(body) == code
+
+
def test_cache_serializes_paid_requests_and_survives_uncertain_results(tmp_path):
db = tmp_path / 'cache.sqlite3'
entered, release = threading.Event(), threading.Event()