go/resources/images/methods/create_variation/index.md +0 −230 deleted
File Deleted View Diff
1## Create image variation
2
3`client.Images.NewVariation(ctx, body) (*ImagesResponse, error)`
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- `body ImageNewVariationParams`
12
13 - `Image param.Field[Reader]`
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 - `Model param.Field[ImageModel]`
18
19 The model to use for image generation. Only `dall-e-2` is supported at this time.
20
21 - `string`
22
23 - `type ImageModel string`
24
25 - `const ImageModelGPTImage1 ImageModel = "gpt-image-1"`
26
27 - `const ImageModelGPTImage1Mini ImageModel = "gpt-image-1-mini"`
28
29 - `const ImageModelGPTImage2 ImageModel = "gpt-image-2"`
30
31 - `const ImageModelGPTImage2_2026_04_21 ImageModel = "gpt-image-2-2026-04-21"`
32
33 - `const ImageModelGPTImage1_5 ImageModel = "gpt-image-1.5"`
34
35 - `const ImageModelChatgptImageLatest ImageModel = "chatgpt-image-latest"`
36
37 - `const ImageModelDallE2 ImageModel = "dall-e-2"`
38
39 - `const ImageModelDallE3 ImageModel = "dall-e-3"`
40
41 - `N param.Field[int64]`
42
43 The number of images to generate. Must be between 1 and 10.
44
45 - `ResponseFormat param.Field[ImageNewVariationParamsResponseFormat]`
46
47 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.
48
49 - `const ImageNewVariationParamsResponseFormatURL ImageNewVariationParamsResponseFormat = "url"`
50
51 - `const ImageNewVariationParamsResponseFormatB64JSON ImageNewVariationParamsResponseFormat = "b64_json"`
52
53 - `Size param.Field[ImageNewVariationParamsSize]`
54
55 The size of the generated images. Must be one of `256x256`, `512x512`, or `1024x1024`.
56
57 - `const ImageNewVariationParamsSize256x256 ImageNewVariationParamsSize = "256x256"`
58
59 - `const ImageNewVariationParamsSize512x512 ImageNewVariationParamsSize = "512x512"`
60
61 - `const ImageNewVariationParamsSize1024x1024 ImageNewVariationParamsSize = "1024x1024"`
62
63 - `User param.Field[string]`
64
65 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).
66
67### Returns
68
69- `type ImagesResponse struct{…}`
70
71 The response from the image generation endpoint.
72
73 - `Created int64`
74
75 The Unix timestamp (in seconds) of when the image was created.
76
77 - `Background ImagesResponseBackground`
78
79 The background parameter used for the image generation. Either `transparent` or `opaque`.
80
81 - `const ImagesResponseBackgroundTransparent ImagesResponseBackground = "transparent"`
82
83 - `const ImagesResponseBackgroundOpaque ImagesResponseBackground = "opaque"`
84
85 - `Data []Image`
86
87 The list of generated images.
88
89 - `B64JSON string`
90
91 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`.
92
93 - `RevisedPrompt string`
94
95 For `dall-e-3` only, the revised prompt that was used to generate the image.
96
97 - `URL string`
98
99 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.
100
101 - `OutputFormat ImagesResponseOutputFormat`
102
103 The output format of the image generation. Either `png`, `webp`, or `jpeg`.
104
105 - `const ImagesResponseOutputFormatPNG ImagesResponseOutputFormat = "png"`
106
107 - `const ImagesResponseOutputFormatWebP ImagesResponseOutputFormat = "webp"`
108
109 - `const ImagesResponseOutputFormatJPEG ImagesResponseOutputFormat = "jpeg"`
110
111 - `Quality ImagesResponseQuality`
112
113 The quality of the image generated. Either `low`, `medium`, or `high`.
114
115 - `const ImagesResponseQualityLow ImagesResponseQuality = "low"`
116
117 - `const ImagesResponseQualityMedium ImagesResponseQuality = "medium"`
118
119 - `const ImagesResponseQualityHigh ImagesResponseQuality = "high"`
120
121 - `Size ImagesResponseSize`
122
123 The size of the image generated. Either `1024x1024`, `1024x1536`, or `1536x1024`.
124
125 - `const ImagesResponseSize1024x1024 ImagesResponseSize = "1024x1024"`
126
127 - `const ImagesResponseSize1024x1536 ImagesResponseSize = "1024x1536"`
128
129 - `const ImagesResponseSize1536x1024 ImagesResponseSize = "1536x1024"`
130
131 - `Usage ImagesResponseUsage`
132
133 For `gpt-image-1` only, the token usage information for the image generation.
134
135 - `InputTokens int64`
136
137 The number of tokens (images and text) in the input prompt.
138
139 - `InputTokensDetails ImagesResponseUsageInputTokensDetails`
140
141 The input tokens detailed information for the image generation.
142
143 - `ImageTokens int64`
144
145 The number of image tokens in the input prompt.
146
147 - `TextTokens int64`
148
149 The number of text tokens in the input prompt.
150
151 - `OutputTokens int64`
152
153 The number of output tokens generated by the model.
154
155 - `TotalTokens int64`
156
157 The total number of tokens (images and text) used for the image generation.
158
159 - `OutputTokensDetails ImagesResponseUsageOutputTokensDetails`
160
161 The output token details for the image generation.
162
163 - `ImageTokens int64`
164
165 The number of image output tokens generated by the model.
166
167 - `TextTokens int64`
168
169 The number of text output tokens generated by the model.
170
171### Example
172
173```go
174package main
175
176import (
177 "bytes"
178 "context"
179 "fmt"
180 "io"
181
182 "github.com/openai/openai-go"
183 "github.com/openai/openai-go/option"
184)
185
186func main() {
187 client := openai.NewClient(
188 option.WithAPIKey("My API Key"),
189 )
190 imagesResponse, err := client.Images.NewVariation(context.TODO(), openai.ImageNewVariationParams{
191 Image: io.Reader(bytes.NewBuffer([]byte("Example data"))),
192 })
193 if err != nil {
194 panic(err.Error())
195 }
196 fmt.Printf("%+v\n", imagesResponse.Created)
197}
198```
199
200#### Response
201
202```json
203{
204 "created": 0,
205 "background": "transparent",
206 "data": [
207 {
208 "b64_json": "b64_json",
209 "revised_prompt": "revised_prompt",
210 "url": "https://example.com"
211 }
212 ],
213 "output_format": "png",
214 "quality": "low",
215 "size": "1024x1024",
216 "usage": {
217 "input_tokens": 0,
218 "input_tokens_details": {
219 "image_tokens": 0,
220 "text_tokens": 0
221 },
222 "output_tokens": 0,
223 "total_tokens": 0,
224 "output_tokens_details": {
225 "image_tokens": 0,
226 "text_tokens": 0
227 }
228 }
229}
230```