java/resources/images/methods/create_variation/index.md +0 −206 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 - `Optional<Long> n`
22
23 The number of images to generate. Must be between 1 and 10.
24
25 - `Optional<ResponseFormat> responseFormat`
26
27 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.
28
29 - `URL("url")`
30
31 - `B64_JSON("b64_json")`
32
33 - `Optional<Size> size`
34
35 The size of the generated images. Must be one of `256x256`, `512x512`, or `1024x1024`.
36
37 - `_256X256("256x256")`
38
39 - `_512X512("512x512")`
40
41 - `_1024X1024("1024x1024")`
42
43 - `Optional<String> user`
44
45 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).
46
47### Returns
48
49- `class ImagesResponse:`
50
51 The response from the image generation endpoint.
52
53 - `long created`
54
55 The Unix timestamp (in seconds) of when the image was created.
56
57 - `Optional<Background> background`
58
59 The background parameter used for the image generation. Either `transparent` or `opaque`.
60
61 - `TRANSPARENT("transparent")`
62
63 - `OPAQUE("opaque")`
64
65 - `Optional<List<Image>> data`
66
67 The list of generated images.
68
69 - `Optional<String> b64Json`
70
71 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`.
72
73 - `Optional<String> revisedPrompt`
74
75 For `dall-e-3` only, the revised prompt that was used to generate the image.
76
77 - `Optional<String> url`
78
79 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.
80
81 - `Optional<OutputFormat> outputFormat`
82
83 The output format of the image generation. Either `png`, `webp`, or `jpeg`.
84
85 - `PNG("png")`
86
87 - `WEBP("webp")`
88
89 - `JPEG("jpeg")`
90
91 - `Optional<Quality> quality`
92
93 The quality of the image generated. Either `low`, `medium`, or `high`.
94
95 - `LOW("low")`
96
97 - `MEDIUM("medium")`
98
99 - `HIGH("high")`
100
101 - `Optional<Size> size`
102
103 The size of the image generated. Either `1024x1024`, `1024x1536`, or `1536x1024`.
104
105 - `_1024X1024("1024x1024")`
106
107 - `_1024X1536("1024x1536")`
108
109 - `_1536X1024("1536x1024")`
110
111 - `Optional<Usage> usage`
112
113 For `gpt-image-1` only, the token usage information for the image generation.
114
115 - `long inputTokens`
116
117 The number of tokens (images and text) in the input prompt.
118
119 - `InputTokensDetails inputTokensDetails`
120
121 The input tokens detailed information for the image generation.
122
123 - `long imageTokens`
124
125 The number of image tokens in the input prompt.
126
127 - `long textTokens`
128
129 The number of text tokens in the input prompt.
130
131 - `long outputTokens`
132
133 The number of output tokens generated by the model.
134
135 - `long totalTokens`
136
137 The total number of tokens (images and text) used for the image generation.
138
139 - `Optional<OutputTokensDetails> outputTokensDetails`
140
141 The output token details for the image generation.
142
143 - `long imageTokens`
144
145 The number of image output tokens generated by the model.
146
147 - `long textTokens`
148
149 The number of text output tokens generated by the model.
150
151### Example
152
153```java
154package com.openai.example;
155
156import com.openai.client.OpenAIClient;
157import com.openai.client.okhttp.OpenAIOkHttpClient;
158import com.openai.models.images.ImageCreateVariationParams;
159import com.openai.models.images.ImagesResponse;
160import java.io.ByteArrayInputStream;
161
162public final class Main {
163 private Main() {}
164
165 public static void main(String[] args) {
166 OpenAIClient client = OpenAIOkHttpClient.fromEnv();
167
168 ImageCreateVariationParams params = ImageCreateVariationParams.builder()
169 .image(new ByteArrayInputStream("Example data".getBytes()))
170 .build();
171 ImagesResponse imagesResponse = client.images().createVariation(params);
172 }
173}
174```
175
176#### Response
177
178```json
179{
180 "created": 0,
181 "background": "transparent",
182 "data": [
183 {
184 "b64_json": "b64_json",
185 "revised_prompt": "revised_prompt",
186 "url": "https://example.com"
187 }
188 ],
189 "output_format": "png",
190 "quality": "low",
191 "size": "1024x1024",
192 "usage": {
193 "input_tokens": 0,
194 "input_tokens_details": {
195 "image_tokens": 0,
196 "text_tokens": 0
197 },
198 "output_tokens": 0,
199 "total_tokens": 0,
200 "output_tokens_details": {
201 "image_tokens": 0,
202 "text_tokens": 0
203 }
204 }
205}
206```