Confirm this is a Node library issue and not an underlying OpenAI API issue
Describe the bug
The SDK type ImageGenerateParamsBase declares
output_format?: 'png' | 'webp' | 'jpeg'
as valid for all GPT image models. In practice, when calling images.generate with model: "gpt-image-2" and output_format: "webp", the API returns PNG-encoded bytes in data[0].b64_json regardless of the requested format. JPEG is honored correctly, so the SDK is sending the field — the API silently ignores webp for this model.
The SDK type therefore lies to callers: the .jpeg path works, the .webp path returns PNG bytes with no error and a misleading filename if you derive the extension from the request.
Two acceptable fixes:
- SDK side — narrow
output_format to 'png' | 'jpeg' for gpt-image-2, surfacing the limitation at compile time.
- API side — honor
output_format: "webp" for gpt-image-2.
To Reproduce
- Call
images.generate with model: "gpt-image-2", output_format: "webp", any quality.
- Decode
result.data[0].b64_json to bytes.
- Inspect the first 8 bytes — they are
89 50 4E 47 0D 0A 1A 0A (PNG magic) instead of 52 49 46 46 .. .. .. .. 57 45 42 50 (RIFF/WEBP).
- Repeat with
output_format: "jpeg" — bytes start with FF D8 FF (JPEG magic) as expected.
Reproduces identically on quality: "auto" | "low" | "medium" | "high".
Code snippets
import OpenAI from "openai";
const client = new OpenAI();
const r = await client.images.generate({
model: "gpt-image-2",
prompt: "solid red square",
size: "1024x1024",
quality: "low",
output_format: "webp",
output_compression: 30,
n: 1,
});
const bytes = Buffer.from(r.data[0].b64_json, "base64");
console.log(bytes.subarray(0, 4).toString("hex")); // "89504e47" → PNG, not WEBP
Raw curl confirms it is API-side, not SDK-side:
curl -X POST https://api.openai.com/v1/images/generations \
-H "Authorization: Bearer \$OPENAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model":"gpt-image-2","prompt":"solid red square",
"size":"1024x1024","quality":"low",
"output_format":"webp","output_compression":30,"n":1
}' | jq -r '.data[0].b64_json' | base64 -d | xxd | head -1
# → 00000000: 8950 4e47 ... (PNG magic, not RIFF/WEBP)
OS
Linux (Deno 1.46+)
Node version
N/A — running Deno via `jsr:@openai/openai@^6`
Library version
openai 6.35.0
Confirm this is a Node library issue and not an underlying OpenAI API issue
Describe the bug
The SDK type
ImageGenerateParamsBasedeclaresas valid for all GPT image models. In practice, when calling
images.generatewithmodel: "gpt-image-2"andoutput_format: "webp", the API returns PNG-encoded bytes indata[0].b64_jsonregardless of the requested format. JPEG is honored correctly, so the SDK is sending the field — the API silently ignoreswebpfor this model.The SDK type therefore lies to callers: the
.jpegpath works, the.webppath returns PNG bytes with no error and a misleading filename if you derive the extension from the request.Two acceptable fixes:
output_formatto'png' | 'jpeg'forgpt-image-2, surfacing the limitation at compile time.output_format: "webp"forgpt-image-2.To Reproduce
images.generatewithmodel: "gpt-image-2",output_format: "webp", any quality.result.data[0].b64_jsonto bytes.89 50 4E 47 0D 0A 1A 0A(PNG magic) instead of52 49 46 46 .. .. .. .. 57 45 42 50(RIFF/WEBP).output_format: "jpeg"— bytes start withFF D8 FF(JPEG magic) as expected.Reproduces identically on
quality: "auto" | "low" | "medium" | "high".Code snippets
Raw curl confirms it is API-side, not SDK-side:
OS
Linux (Deno 1.46+)
Node version
N/A — running Deno via `jsr:@openai/openai@^6`
Library version
openai 6.35.0