conductor-oss/conductor · error · IOException

Stability AI API returned empty response body

Error message

Stability AI API returned empty response body

What it means

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/*).

Source

Thrown at ai/src/main/java/org/conductoross/conductor/ai/providers/stabilityai/StabilityAiApi.java:136

                        .build();

        log.info(
                "Stability AI image generation request: endpoint={}, model={}, outputFormat={}",
                endpoint,
                params.model(),
                outputFormat);

        try (Response response = httpClient.newCall(request).execute()) {
            if (!response.isSuccessful()) {
                String errorBody = readResponseBody(response);
                throw new IOException(
                        "Stability AI API failed with status %d: %s"
                                .formatted(response.code(), errorBody));
            }

            ResponseBody body = response.body();
            if (body == null) {
                throw new IOException("Stability AI API returned empty response body");
            }

            // Determine the actual content type returned
            String contentType = response.header("Content-Type", "image/" + outputFormat);
            // Read the finish-reason header (e.g., SUCCESS, CONTENT_FILTERED)
            String finishReason = response.header("finish-reason", "SUCCESS");
            // Read the seed header
            String seedHeader = response.header("seed");

            byte[] imageBytes = body.bytes();
            log.info(
                    "Stability AI image generated: {} bytes, contentType={}, finishReason={}",
                    imageBytes.length,
                    contentType,
                    finishReason);

            return new ImageResult(imageBytes, contentType, finishReason, seedHeader);
        }

View on GitHub (pinned to cf7c3e4a8a)

Solutions

  1. Call api.stability.ai directly to confirm the body is returned.
  2. Audit OkHttp interceptors on the shared client for premature body reads.
  3. Ensure the gateway passes binary image content through unchanged.
Defensive patterns

Strategy: try-catch

Try / catch

try {
    ImageResult img = api.generateImage(params);
} catch (IOException e) {
    if (e.getMessage().contains("empty response body")) {
        // proxy stripped body; retry against direct endpoint
    } else {
        throw e;
    }
}

Prevention

When it happens

Trigger: A proxy/gateway returns 200 with no binary body for the image endpoint, or an OkHttp interceptor consumes the body before generateImage reads it.

Common situations: Corporate proxy stripping binary responses, a CDN misconfiguration, or shared httpClient logging interceptors that fully drain the body.

Related errors


AI-assisted analysis of conductor-oss/conductor@cf7c3e4a8a (2026-08-14). Data as JSON: /api/errors/e4b78fb4302b372c. Report an issue: GitHub.