{"record":{"id":"b9b6f427c9e599f2","repo":"unslothai/unsloth","slug":"sd-server-img-gen-returned-a-non-json-submit-respo","errorCode":null,"errorMessage":"sd-server img_gen returned a non-JSON submit response: {exc}","messagePattern":"sd-server img_gen returned a non-JSON submit response: (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"studio/backend/core/inference/sd_cpp_server.py","lineNumber":474,"sourceCode":"        job_id: Optional[str] = None\n        try:\n            # Submit -> 202 Accepted + job id.\n            try:\n                resp = self._client.post(\n                    f\"{self.base_url}{_IMG_GEN_PATH}\", json = payload, timeout = submit_timeout\n                )\n            except (*_TRANSPORT_ERRORS, httpx.TimeoutException) as exc:\n                raise RuntimeError(self._died_message(\"img_gen submit\", exc)) from exc\n            if resp.status_code == 429:\n                raise RuntimeError(\"sd-server job queue is full (HTTP 429).\")\n            if resp.status_code not in (200, 202):\n                raise RuntimeError(\n                    f\"sd-server img_gen submit -> {resp.status_code}: {resp.text[:500]}\"\n                )\n            try:\n                job = resp.json()\n            except ValueError as exc:\n                raise RuntimeError(\n                    f\"sd-server img_gen returned a non-JSON submit response: {exc}\"\n                ) from exc\n            if not isinstance(job, dict):\n                raise RuntimeError(\n                    f\"sd-server img_gen returned an unexpected submit response type: {type(job)}\"\n                )\n            job_id = job.get(\"id\")\n            if not job_id:\n                raise RuntimeError(f\"sd-server img_gen returned no job id: {job}\")\n\n            # Poll the job to a terminal state.\n            deadline = time.monotonic() + total_timeout\n            cancel_sent_at: Optional[float] = None\n            while True:\n                if cancel_event is not None and cancel_event.is_set():\n                    if cancel_sent_at is None:\n                        self.cancel(job_id)\n                        cancel_sent_at = time.monotonic()","sourceCodeStart":456,"sourceCodeEnd":492,"githubUrl":"https://github.com/unslothai/unsloth/blob/203007d19051dcd2ae33876786d117c99f6b0368/studio/backend/core/inference/sd_cpp_server.py#L456-L492","documentation":"The submit response had a success status but resp.json() raised ValueError — the body is not valid JSON. This means whatever answered on the server port is not speaking the sd-server API: a misconfigured base_url pointing at a different service, a proxy or captive portal intercepting the request, or a corrupted response. The parser exception is chained for details.","triggerScenarios":"The base_url/port belongs to another HTTP server (any JSON-unaware service, an HTML error page returning 200); a reverse proxy rewriting responses; port collision where an unrelated process bound the expected port.","commonSituations":"Port configuration drift after server restart picks a different port; a corporate proxy returning an HTML auth page; two sd-server instances with stale URL cached client-side.","solutions":["Verify the base URL actually points at the sd-server instance you started (fetch /v1/models and check the JSON shape).","Bypass or configure proxies for the localhost server port (NO_PROXY for 127.0.0.1).","If a port collision, restart the server so it reports its real port and use that URL."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"import httpx\nr = httpx.get(f\"{base_url}/v1/models\", timeout=5)\nassert r.status_code == 200 and r.headers.get(\"content-type\", \"\").startswith(\"application/json\"), \\\n    f\"{base_url} is not an sd-server instance\"","typeGuard":null,"tryCatchPattern":"try:\n    blobs = server.img_gen(payload, ...)\nexcept RuntimeError as e:\n    if \"non-JSON submit response\" in str(e):\n        verify_base_url_points_at_sd_server()\n    raise","preventionTips":["Health-check /v1/models for JSON before using a configured base_url.","Exclude localhost from HTTP proxies (NO_PROXY) in corporate environments.","Always derive the URL from the server instance you started, never hardcode a port."],"tags":["diffusion","sd-cpp","server","json","configuration"],"backgroundTag":null,"analyzedSha":"203007d19051dcd2ae33876786d117c99f6b0368","analyzedAt":"2026-08-15T02:48:39.846Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}