{"record":{"id":"d935be79eda65229","repo":"Comfy-Org/ComfyUI","slug":"sonilo-api-error-resp-status-msg","errorCode":null,"errorMessage":"Sonilo API error ({resp.status}): {msg}","messagePattern":"Sonilo API error \\((.+?)\\): (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"comfy_api_nodes/nodes_sonilo.py","lineNumber":183,"sourceCode":"    \"\"\"POST ``form`` to Sonilo, read the NDJSON stream, and return the first stream's audio bytes.\"\"\"\n    url = urljoin(default_base_url().rstrip(\"/\") + \"/\", endpoint.path.lstrip(\"/\"))\n\n    headers = get_comfy_api_headers(cls)\n    headers.update(endpoint.headers)\n\n    node_id = get_node_id(cls)\n    start_ts = time.monotonic()\n    last_chunk_status_ts = 0.0\n    audio_streams: dict[int, list[bytes]] = {}\n    title: str | None = None\n\n    timeout = aiohttp.ClientTimeout(total=1200.0, sock_read=300.0)\n    async with aiohttp.ClientSession(timeout=timeout) as session:\n        PromptServer.instance.send_progress_text(\"Status: Queued\", node_id)\n        async with session.post(url, data=form, headers=headers) as resp:\n            if resp.status >= 400:\n                msg = await _extract_error_message(resp)\n                raise Exception(f\"Sonilo API error ({resp.status}): {msg}\")\n\n            while True:\n                if is_processing_interrupted():\n                    raise ProcessingInterrupted(\"Task cancelled\")\n\n                raw_line = await resp.content.readline()\n                if not raw_line:\n                    break\n\n                line = raw_line.decode(\"utf-8\").strip()\n                if not line:\n                    continue\n\n                try:\n                    evt = json.loads(line)\n                except json.JSONDecodeError:\n                    logger.warning(\"Sonilo: skipping malformed NDJSON line\")\n                    continue","sourceCodeStart":165,"sourceCodeEnd":201,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy_api_nodes/nodes_sonilo.py#L165-L201","documentation":"Raised by the Sonilo node when the initial HTTP POST to the Sonilo endpoint returns a status >= 400. The response body is parsed by _extract_error_message (looking for a JSON `detail` field) and embedded into the raised message. This is the entry-point failure for the streaming NDJSON music generation call.","triggerScenarios":"POSTing the multipart form to the Sonilo API url with an expired/invalid token, malformed form fields, or a server-side error, yielding HTTP 4xx/5xx; _extract_error_message then formats the body.","commonSituations":"Invalid or expired Sonilo API key/headers; wrong endpoint url; prompt or parameter rejected with 422; Sonilo service outage returning 5xx.","solutions":["Check the embedded msg and status: 401/403 means fix the API key/headers, 422 means fix form parameters","Verify the Sonilo endpoint URL is current","For 5xx, wait and retry — server-side issue"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"headers[\"Authorization\"] = f\"Bearer {os.environ['SONILO_API_KEY']}\"  # fail fast if key missing\nassert form is not None and url.startswith(\"https://\"), \"valid Sonilo endpoint and form required\"","typeGuard":null,"tryCatchPattern":"try:\n    audio = await _sonilo_generate(url, form, headers)\nexcept Exception as e:\n    msg = str(e)\n    if \"Sonilo API error (401)\" in msg or \"(403)\" in msg:\n        refresh_sonilo_credentials()\n    elif \"(4\" in msg:\n        raise ValueError(f\"Bad Sonilo request: {msg}\") from e\n    else:\n        raise","preventionTips":["Validate the API key and endpoint URL before starting long workflows","Surface the status code and detail message — they distinguish auth, validation, and outage","Do not retry 4xx blindly; only 5xx statuses are retryable"],"tags":["sonilo","http","api-error","music-generation"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}