java/resources/images/methods/create_variation/index.md +0 −222 deleted
File Deleted View Diff
1## Create image variation
2
3`ImagesResponse images().createVariation(ImageCreateVariationParamsparams, RequestOptionsrequestOptions = RequestOptions.none())`
4
5**post** `/images/variations`
6
7Creates a variation of a given image. This endpoint only supports `dall-e-2`.
8
9### Parameters
10
11- `ImageCreateVariationParams params`
12
13 - `String image`
14
15 The image to use as the basis for the variation(s). Must be a valid PNG file, less than 4MB, and square.
16
17 - `Optional<ImageModel> model`
18
19 The model to use for image generation. Only `dall-e-2` is supported at this time.
20
21 - `GPT_IMAGE_1("gpt-image-1")`
22
23 - `GPT_IMAGE_1_MINI("gpt-image-1-mini")`
24
25 - `GPT_IMAGE_2("gpt-image-2")`
26
27 - `GPT_IMAGE_2_2026_04_21("gpt-image-2-2026-04-21")`
28
29 - `GPT_IMAGE_1_5("gpt-image-1.5")`
30
31 - `CHATGPT_IMAGE_LATEST("chatgpt-image-latest")`
32
33 - `DALL_E_2("dall-e-2")`
34
35 - `DALL_E_3("dall-e-3")`
36
37 - `Optional<Long> n`
38
39 The number of images to generate. Must be between 1 and 10.
40
41 - `Optional<ResponseFormat> responseFormat`
42
43 The format in which the generated images are returned. Must be one of `url` or `b64_json`. URLs are only valid for 60 minutes after the image has been generated.
44
45 - `URL("url")`
46
47 - `B64_JSON("b64_json")`
48
49 - `Optional<Size> size`
50
51 The size of the generated images. Must be one of `256x256`, `512x512`, or `1024x1024`.
52
53 - `_256X256("256x256")`
54
55 - `_512X512("512x512")`
56
57 - `_1024X1024("1024x1024")`
58
59 - `Optional<String> user`
60
61 A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#end-user-ids).
62
63### Returns
64
65- `class ImagesResponse:`
66
67 The response from the image generation endpoint.
68
69 - `long created`
70
71 The Unix timestamp (in seconds) of when the image was created.
72
73 - `Optional<Background> background`
74
75 The background parameter used for the image generation. Either `transparent` or `opaque`.
76
77 - `TRANSPARENT("transparent")`
78
79 - `OPAQUE("opaque")`
80
81 - `Optional<List<Image>> data`
82
83 The list of generated images.
84
85 - `Optional<String> b64Json`
86
87 The base64-encoded JSON of the generated image. Returned by default for the GPT image models, and only present if `response_format` is set to `b64_json` for `dall-e-2` and `dall-e-3`.
88
89 - `Optional<String> revisedPrompt`
90
91 For `dall-e-3` only, the revised prompt that was used to generate the image.
92
93 - `Optional<String> url`
94
95 When using `dall-e-2` or `dall-e-3`, the URL of the generated image if `response_format` is set to `url` (default value). Unsupported for the GPT image models.
96
97 - `Optional<OutputFormat> outputFormat`
98
99 The output format of the image generation. Either `png`, `webp`, or `jpeg`.
100
101 - `PNG("png")`
102
103 - `WEBP("webp")`
104
105 - `JPEG("jpeg")`
106
107 - `Optional<Quality> quality`
108
109 The quality of the image generated. Either `low`, `medium`, or `high`.
110
111 - `LOW("low")`
112
113 - `MEDIUM("medium")`
114
115 - `HIGH("high")`
116
117 - `Optional<Size> size`
118
119 The size of the image generated. Either `1024x1024`, `1024x1536`, or `1536x1024`.
120
121 - `_1024X1024("1024x1024")`
122
123 - `_1024X1536("1024x1536")`
124
125 - `_1536X1024("1536x1024")`
126
127 - `Optional<Usage> usage`
128
129 For `gpt-image-1` only, the token usage information for the image generation.
130
131 - `long inputTokens`
132
133 The number of tokens (images and text) in the input prompt.
134
135 - `InputTokensDetails inputTokensDetails`
136
137 The input tokens detailed information for the image generation.
138
139 - `long imageTokens`
140
141 The number of image tokens in the input prompt.
142
143 - `long textTokens`
144
145 The number of text tokens in the input prompt.
146
147 - `long outputTokens`
148
149 The number of output tokens generated by the model.
150
151 - `long totalTokens`
152
153 The total number of tokens (images and text) used for the image generation.
154
155 - `Optional<OutputTokensDetails> outputTokensDetails`
156
157 The output token details for the image generation.
158
159 - `long imageTokens`
160
161 The number of image output tokens generated by the model.
162
163 - `long textTokens`
164
165 The number of text output tokens generated by the model.
166
167### Example
168
169```java
170package com.openai.example;
171
172import com.openai.client.OpenAIClient;
173import com.openai.client.okhttp.OpenAIOkHttpClient;
174import com.openai.models.images.ImageCreateVariationParams;
175import com.openai.models.images.ImagesResponse;
176import java.io.ByteArrayInputStream;
177
178public final class Main {
179 private Main() {}
180
181 public static void main(String[] args) {
182 OpenAIClient client = OpenAIOkHttpClient.fromEnv();
183
184 ImageCreateVariationParams params = ImageCreateVariationParams.builder()
185 .image(new ByteArrayInputStream("Example data".getBytes()))
186 .build();
187 ImagesResponse imagesResponse = client.images().createVariation(params);
188 }
189}
190```
191
192#### Response
193
194```json
195{
196 "created": 0,
197 "background": "transparent",
198 "data": [
199 {
200 "b64_json": "b64_json",
201 "revised_prompt": "revised_prompt",
202 "url": "https://example.com"
203 }
204 ],
205 "output_format": "png",
206 "quality": "low",
207 "size": "1024x1024",
208 "usage": {
209 "input_tokens": 0,
210 "input_tokens_details": {
211 "image_tokens": 0,
212 "text_tokens": 0
213 },
214 "output_tokens": 0,
215 "total_tokens": 0,
216 "output_tokens_details": {
217 "image_tokens": 0,
218 "text_tokens": 0
219 }
220 }
221}
222```