{"record":{"id":"e4b78fb4302b372c","repo":"conductor-oss/conductor","slug":"stability-ai-api-returned-empty-response-body","errorCode":null,"errorMessage":"Stability AI API returned empty response body","messagePattern":"Stability AI API returned empty response body","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"ai/src/main/java/org/conductoross/conductor/ai/providers/stabilityai/StabilityAiApi.java","lineNumber":136,"sourceCode":"                        .build();\n\n        log.info(\n                \"Stability AI image generation request: endpoint={}, model={}, outputFormat={}\",\n                endpoint,\n                params.model(),\n                outputFormat);\n\n        try (Response response = httpClient.newCall(request).execute()) {\n            if (!response.isSuccessful()) {\n                String errorBody = readResponseBody(response);\n                throw new IOException(\n                        \"Stability AI API failed with status %d: %s\"\n                                .formatted(response.code(), errorBody));\n            }\n\n            ResponseBody body = response.body();\n            if (body == null) {\n                throw new IOException(\"Stability AI API returned empty response body\");\n            }\n\n            // Determine the actual content type returned\n            String contentType = response.header(\"Content-Type\", \"image/\" + outputFormat);\n            // Read the finish-reason header (e.g., SUCCESS, CONTENT_FILTERED)\n            String finishReason = response.header(\"finish-reason\", \"SUCCESS\");\n            // Read the seed header\n            String seedHeader = response.header(\"seed\");\n\n            byte[] imageBytes = body.bytes();\n            log.info(\n                    \"Stability AI image generated: {} bytes, contentType={}, finishReason={}\",\n                    imageBytes.length,\n                    contentType,\n                    finishReason);\n\n            return new ImageResult(imageBytes, contentType, finishReason, seedHeader);\n        }","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/conductor-oss/conductor/blob/cf7c3e4a8adfb158be778ab1ec525323c363cd3a/ai/src/main/java/org/conductoross/conductor/ai/providers/stabilityai/StabilityAiApi.java#L118-L154","documentation":"Thrown by StabilityAiApi.generateImage when the v2beta endpoint returns 2xx but response.body() is null. Defensive guard for abnormal gateway/proxy behavior on the binary image response (requested with Accept: image/*).","triggerScenarios":"A proxy/gateway returns 200 with no binary body for the image endpoint, or an OkHttp interceptor consumes the body before generateImage reads it.","commonSituations":"Corporate proxy stripping binary responses, a CDN misconfiguration, or shared httpClient logging interceptors that fully drain the body.","solutions":["Call api.stability.ai directly to confirm the body is returned.","Audit OkHttp interceptors on the shared client for premature body reads.","Ensure the gateway passes binary image content through unchanged."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    ImageResult img = api.generateImage(params);\n} catch (IOException e) {\n    if (e.getMessage().contains(\"empty response body\")) {\n        // proxy stripped body; retry against direct endpoint\n    } else {\n        throw e;\n    }\n}","preventionTips":["Avoid OkHttp interceptors that consume response bodies.","Verify proxies forward binary image content unchanged.","Test against api.stability.ai directly first."],"tags":["stabilityai","image-generation","empty-body","proxy","http"],"backgroundTag":null,"analyzedSha":"cf7c3e4a8adfb158be778ab1ec525323c363cd3a","analyzedAt":"2026-08-14T03:33:19.897Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}