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
- 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.
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
- Avoid OkHttp interceptors that consume response bodies.
- Verify proxies forward binary image content unchanged.
- Test against api.stability.ai directly first.
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
- Speech API returned empty body
- Stability AI API failed with status %d: %s
- OpenAI Video download returned empty body
- OpenAI Video thumbnail download returned empty body
- Stability AI image generation failed:
AI-assisted analysis of conductor-oss/conductor@cf7c3e4a8a (2026-08-14).
Data as JSON: /api/errors/e4b78fb4302b372c.
Report an issue: GitHub.