harry0703/MoneyPrinterTurbo · error · SoniloError
Sonilo generation failed ({response.status_code}): {_safe_re
Error message
Sonilo generation failed ({response.status_code}): {_safe_response_error(response)} What it means
Raised when POST /v1/video-to-music returns a non-2xx HTTP status. The message includes the status code and up to 500 characters of the response body (via _safe_response_error, falling back to the reason phrase). Common codes: 401 bad key, 402/429 quota or rate limit, 413 proxy too large, 422 validation, 5xx provider.
Source
Thrown at app/services/sonilo.py:298
os.close(descriptor)
try:
logger.info(
f"requesting Sonilo background music: video={video_path}, "
f"prompt_provided={bool(prompt)}"
)
try:
with open(video_path, "rb") as video_file:
response = requests.post(
f"{_base_url()}{VIDEO_TO_MUSIC_PATH}",
headers={"Authorization": f"Bearer {get_api_key()}"},
files={"video": (Path(video_path).name, video_file, "video/mp4")},
data={"prompt": prompt} if prompt else None,
stream=True,
timeout=_request_timeout(),
)
with response:
if not response.ok:
raise SoniloError(
f"Sonilo generation failed ({response.status_code}): "
f"{_safe_response_error(response)}"
)
total_bytes, title = _stream_audio(response, temp_audio_path)
except requests.RequestException as exc:
# iter_lines() 期间的网络中断同样属于 requests 异常,不能只捕获
# 建立连接阶段,否则半条音频可能让任务直接异常退出而无法降级。
raise SoniloError(f"failed to request Sonilo 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 SoniloError("Sonilo returned audio that FFmpeg cannot decode") from exc
os.replace(temp_audio_path, output_path)
temp_audio_path = ""
logger.info(
f"Sonilo background music generated: output={output_path}, "
f"size={total_bytes} bytes, title={title or '-'}"View on GitHub (pinned to 1f9f19c202)
Solutions
- Read the status code in the message: 401 fix the key; 402/429 quota or rate, back off or top up; 413 shrink the proxy; 422 check video duration (max 360) and prompt length (max 2000); 5xx retry later.
- Re-run the connection test to verify the key independently of the upload path.
- For 413, tighten proxy encoding (see error 85) or check Sonilo's documented upload cap.
- For 5xx, add retry with backoff around the generation call rather than failing the whole task.
Defensive patterns
Strategy: try-catch
Validate before calling
# pre-flight the cheap endpoint and bounds before the expensive upload sonilo.test_connection() # catches 401/entitlement early assert probe_duration_seconds(video) <= sonilo.MAX_VIDEO_DURATION_SECONDS assert len(prompt or "") <= sonilo.MAX_PROMPT_LENGTH
Try / catch
import re
try:
audio = request_bgm(video, out, prompt)
except SoniloError as exc:
m = re.search(r"Sonilo generation failed \((\d{3})\)", str(exc))
if m:
status = int(m.group(1))
if status in (429, 500, 502, 503):
schedule_retry_with_backoff() # transient
elif status in (401, 402):
fail_task_and_alert_owner(status) # credential/quota: never retry
elif status == 413:
re_encode_proxy_smaller()
raise Prevention
- Map every status code to a policy (retry, fix input, or alert) instead of a blanket retry.
- Run the connection test at task submission so 401s surface before minutes of proxy generation are spent.
When it happens
Trigger: Invalid or revoked API key (401); expired credits (402) or rate limit (429); video proxy exceeding the provider's upload limit (413); video longer than 360 seconds or prompt over 2000 chars (422); provider outage (5xx). Each surfaces with its status code in the message.
Common situations: Key rotated but the WebUI config still holds the old value; sudden 429s after increasing task concurrency; large source videos producing proxies over the provider limit; provider-side incidents.
Related errors
- Sonilo API key is required
- Sonilo connection failed ({response.status_code}): {_safe_re
- Sonilo video-to-music service is not available for this key
- invalid token: {request_url}, {user_agent}
- {request_id}: invalid filename
AI-assisted analysis of harry0703/MoneyPrinterTurbo@1f9f19c202 (2026-08-14).
Data as JSON: /api/errors/1b907f143c7872d8.
Report an issue: GitHub.