harry0703/MoneyPrinterTurbo · error · ElevenLabsMusicError
failed to request ElevenLabs music: {exc}
Error message
failed to request ElevenLabs music: {exc} What it means
Wraps any requests.RequestException (DNS failure, connection reset, TLS error, read timeout from the (15, <=1800s) timeout tuple, or a dropped stream mid-download) raised while POSTing to ElevenLabs or streaming the audio body back. Wrapping it in ElevenLabsMusicError forces the task into its degradation logic instead of failing an already-rendered video because of third-party network churn.
Source
Thrown at app/services/elevenlabs_music.py:342
(Path(video_path).name, video_file, "video/mp4"),
)
],
data=request_data,
stream=True,
timeout=_request_timeout(),
)
with response:
if not response.ok:
raise ElevenLabsMusicError(
"ElevenLabs generation failed "
f"({response.status_code}): "
f"{_safe_response_error(response)}"
)
total_bytes = _stream_audio(response, temp_audio_path)
except requests.RequestException as exc:
# 下载阶段断线也属于请求失败,必须进入任务降级逻辑,不能留下半条
# 音频或让已经生成的视频因为第三方网络波动整体失败。
raise ElevenLabsMusicError(
f"failed to request ElevenLabs music: {exc}"
) from exc
try:
bgm_service.validate_audio_file(temp_audio_path, timeout_seconds=120)
except (bgm_service.BgmUploadError, bgm_service.BgmServiceError) as exc:
raise ElevenLabsMusicError(
"ElevenLabs returned audio that FFmpeg cannot decode"
) from exc
os.replace(temp_audio_path, output_path)
temp_audio_path = ""
logger.info(
"ElevenLabs background music generated: "
f"output={output_path}, size={total_bytes} bytes"
)
return output_path
finally:
_remove_file(temp_audio_path)View on GitHub (pinned to 1f9f19c202)
Solutions
- Retry the generation once or twice with backoff — the error is explicitly treated as transient degradation, not a hard failure
- Increase the elevenlabs.music_timeout config value if the read timeout fires on long videos (it is capped at 1800s)
- Verify network egress to api.elevenlabs.io (curl -I https://api.elevenlabs.io) and fix proxy/DNS if the connection never opens
- If it fails repeatedly, let the task fall back to no-BGM output rather than aborting the rendered video
Example fix
# before
path = _request_bgm(proxy_path, output_path, prompt)
# after
for attempt in range(2):
try:
path = _request_bgm(proxy_path, output_path, prompt)
break
except ElevenLabsMusicError as exc:
if attempt == 1:
raise
time.sleep(10) Defensive patterns
Strategy: retry
Validate before calling
import socket, urllib.parse
host = urllib.parse.urlparse("https://api.elevenlabs.io").hostname
socket.gethostbyname(host) # fail fast on DNS problems Try / catch
for attempt in range(3):
try:
return elm.generate_bgm(video, out, duration, prompt)
except elm.ElevenLabsMusicError as e:
if attempt == 2 or not is_transient(e):
return fallback_no_bgm()
time.sleep(2 ** attempt * 5) Prevention
- Size elevenlabs.music_timeout generously for long videos (cap 1800s)
- Run generation with retry + exponential backoff wrapped around generate_bgm
- Degrade to no-BGM output on repeated network failure rather than failing the video
When it happens
Trigger: Any requests exception during the streaming POST /v1/music/video-to-music or during _stream_audio: ConnectionError (no route to api.elevenlabs.io), ChunkedEncodingError (server closed the stream mid-audio), ReadTimeout when generation exceeds the configured music_timeout read timeout.
Common situations: Corporate proxies/firewalls blocking api.elevenlabs.io, flaky home uplinks dropping long streams, music_timeout set too low for long videos (600s content can take minutes), DNS failures in containers.
Related errors
- failed to connect to ElevenLabs: {exc}
- ElevenLabs audio exceeds the 50 MB limit
- Sonilo returned malformed streaming data
- Sonilo stream ended before completion
- failed to request Sonilo music: {exc}
AI-assisted analysis of harry0703/MoneyPrinterTurbo@1f9f19c202 (2026-08-14).
Data as JSON: /api/errors/16d23dec395a3ec3.
Report an issue: GitHub.