Skip to content

images.generate types advertise output_format="webp" for gpt-image-2, but API ignores it and returns PNG #1850

Description

@pedrobarretocw

Confirm this is a Node library issue and not an underlying OpenAI API issue

  • This is an issue with the Node library

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:

  1. SDK side — narrow output_format to 'png' | 'jpeg' for gpt-image-2, surfacing the limitation at compile time.
  2. API side — honor output_format: "webp" for gpt-image-2.

To Reproduce

  1. Call images.generate with model: "gpt-image-2", output_format: "webp", any quality.
  2. Decode result.data[0].b64_json to bytes.
  3. 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).
  4. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    openai apiRelated to underlying OpenAI API

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions