Create image
client.images.generate(ImageGenerateParamsbody , RequestOptionsoptions ?): ImagesResponse { created, background, data, 6 more } | Stream<ImageGenStreamEvent>
POST
/images/generationsCreates an image given a prompt using a GPT Image model. Learn more.
Create image
import OpenAI from "openai";
import { writeFile } from "fs/promises";
const client = new OpenAI();
const img = await client.images.generate({
model: "gpt-image-2.6-flare",
prompt: "A cute baby sea otter",
n: 1,
size: "1024x1024"
});
const imageBuffer = Buffer.from(img.data[0].b64_json, "base64");
await writeFile("output.png", imageBuffer);
Response example
{
"created": 1713833628,
"data": [
{
"b64_json": "..."
}
],
"usage": {
"total_tokens": 100,
"input_tokens": 50,
"output_tokens": 50,
"input_tokens_details": {
"text_tokens": 10,
"image_tokens": 40
}
}
}
Returns Examples
200 — Example
{
"created": 0,
"background": "transparent",
"data": [
{
"b64_json": "b64_json",
"revised_prompt": "revised_prompt",
"url": "https://example.com"
}
],
"output_format": "png",
"quality": "low",
"safety_identifier": "safety_identifier",
"size": "1024x1024",
"svg_usage": {
"input_tokens": 0,
"model": "model",
"output_tokens": 0,
"reasoning_tokens": 0,
"total_tokens": 0
},
"usage": {
"input_tokens": 0,
"input_tokens_details": {
"image_tokens": 0,
"text_tokens": 0
},
"output_tokens": 0,
"total_tokens": 0,
"output_tokens_details": {
"image_tokens": 0,
"text_tokens": 0
}
}
}