image.go

  1// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
  2
  3package openai
  4
  5import (
  6	"bytes"
  7	"context"
  8	"io"
  9	"mime/multipart"
 10	"net/http"
 11
 12	"github.com/openai/openai-go/internal/apiform"
 13	"github.com/openai/openai-go/internal/apijson"
 14	"github.com/openai/openai-go/internal/requestconfig"
 15	"github.com/openai/openai-go/option"
 16	"github.com/openai/openai-go/packages/param"
 17	"github.com/openai/openai-go/packages/respjson"
 18)
 19
 20// ImageService contains methods and other services that help with interacting with
 21// the openai API.
 22//
 23// Note, unlike clients, this service does not read variables from the environment
 24// automatically. You should not instantiate this service directly, and instead use
 25// the [NewImageService] method instead.
 26type ImageService struct {
 27	Options []option.RequestOption
 28}
 29
 30// NewImageService generates a new service that applies the given options to each
 31// request. These options are applied after the parent client's options (if there
 32// is one), and before any request-specific options.
 33func NewImageService(opts ...option.RequestOption) (r ImageService) {
 34	r = ImageService{}
 35	r.Options = opts
 36	return
 37}
 38
 39// Creates a variation of a given image. This endpoint only supports `dall-e-2`.
 40func (r *ImageService) NewVariation(ctx context.Context, body ImageNewVariationParams, opts ...option.RequestOption) (res *ImagesResponse, err error) {
 41	opts = append(r.Options[:], opts...)
 42	path := "images/variations"
 43	err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
 44	return
 45}
 46
 47// Creates an edited or extended image given one or more source images and a
 48// prompt. This endpoint only supports `gpt-image-1` and `dall-e-2`.
 49func (r *ImageService) Edit(ctx context.Context, body ImageEditParams, opts ...option.RequestOption) (res *ImagesResponse, err error) {
 50	opts = append(r.Options[:], opts...)
 51	path := "images/edits"
 52	err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
 53	return
 54}
 55
 56// Creates an image given a prompt.
 57// [Learn more](https://platform.openai.com/docs/guides/images).
 58func (r *ImageService) Generate(ctx context.Context, body ImageGenerateParams, opts ...option.RequestOption) (res *ImagesResponse, err error) {
 59	opts = append(r.Options[:], opts...)
 60	path := "images/generations"
 61	err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
 62	return
 63}
 64
 65// Represents the content or the URL of an image generated by the OpenAI API.
 66type Image struct {
 67	// The base64-encoded JSON of the generated image. Default value for `gpt-image-1`,
 68	// and only present if `response_format` is set to `b64_json` for `dall-e-2` and
 69	// `dall-e-3`.
 70	B64JSON string `json:"b64_json"`
 71	// For `dall-e-3` only, the revised prompt that was used to generate the image.
 72	RevisedPrompt string `json:"revised_prompt"`
 73	// When using `dall-e-2` or `dall-e-3`, the URL of the generated image if
 74	// `response_format` is set to `url` (default value). Unsupported for
 75	// `gpt-image-1`.
 76	URL string `json:"url"`
 77	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
 78	JSON struct {
 79		B64JSON       respjson.Field
 80		RevisedPrompt respjson.Field
 81		URL           respjson.Field
 82		ExtraFields   map[string]respjson.Field
 83		raw           string
 84	} `json:"-"`
 85}
 86
 87// Returns the unmodified JSON received from the API
 88func (r Image) RawJSON() string { return r.JSON.raw }
 89func (r *Image) UnmarshalJSON(data []byte) error {
 90	return apijson.UnmarshalRoot(data, r)
 91}
 92
 93type ImageModel = string
 94
 95const (
 96	ImageModelDallE2    ImageModel = "dall-e-2"
 97	ImageModelDallE3    ImageModel = "dall-e-3"
 98	ImageModelGPTImage1 ImageModel = "gpt-image-1"
 99)
100
101// The response from the image generation endpoint.
102type ImagesResponse struct {
103	// The Unix timestamp (in seconds) of when the image was created.
104	Created int64 `json:"created,required"`
105	// The background parameter used for the image generation. Either `transparent` or
106	// `opaque`.
107	//
108	// Any of "transparent", "opaque".
109	Background ImagesResponseBackground `json:"background"`
110	// The list of generated images.
111	Data []Image `json:"data"`
112	// The output format of the image generation. Either `png`, `webp`, or `jpeg`.
113	//
114	// Any of "png", "webp", "jpeg".
115	OutputFormat ImagesResponseOutputFormat `json:"output_format"`
116	// The quality of the image generated. Either `low`, `medium`, or `high`.
117	//
118	// Any of "low", "medium", "high".
119	Quality ImagesResponseQuality `json:"quality"`
120	// The size of the image generated. Either `1024x1024`, `1024x1536`, or
121	// `1536x1024`.
122	//
123	// Any of "1024x1024", "1024x1536", "1536x1024".
124	Size ImagesResponseSize `json:"size"`
125	// For `gpt-image-1` only, the token usage information for the image generation.
126	Usage ImagesResponseUsage `json:"usage"`
127	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
128	JSON struct {
129		Created      respjson.Field
130		Background   respjson.Field
131		Data         respjson.Field
132		OutputFormat respjson.Field
133		Quality      respjson.Field
134		Size         respjson.Field
135		Usage        respjson.Field
136		ExtraFields  map[string]respjson.Field
137		raw          string
138	} `json:"-"`
139}
140
141// Returns the unmodified JSON received from the API
142func (r ImagesResponse) RawJSON() string { return r.JSON.raw }
143func (r *ImagesResponse) UnmarshalJSON(data []byte) error {
144	return apijson.UnmarshalRoot(data, r)
145}
146
147// The background parameter used for the image generation. Either `transparent` or
148// `opaque`.
149type ImagesResponseBackground string
150
151const (
152	ImagesResponseBackgroundTransparent ImagesResponseBackground = "transparent"
153	ImagesResponseBackgroundOpaque      ImagesResponseBackground = "opaque"
154)
155
156// The output format of the image generation. Either `png`, `webp`, or `jpeg`.
157type ImagesResponseOutputFormat string
158
159const (
160	ImagesResponseOutputFormatPNG  ImagesResponseOutputFormat = "png"
161	ImagesResponseOutputFormatWebP ImagesResponseOutputFormat = "webp"
162	ImagesResponseOutputFormatJPEG ImagesResponseOutputFormat = "jpeg"
163)
164
165// The quality of the image generated. Either `low`, `medium`, or `high`.
166type ImagesResponseQuality string
167
168const (
169	ImagesResponseQualityLow    ImagesResponseQuality = "low"
170	ImagesResponseQualityMedium ImagesResponseQuality = "medium"
171	ImagesResponseQualityHigh   ImagesResponseQuality = "high"
172)
173
174// The size of the image generated. Either `1024x1024`, `1024x1536`, or
175// `1536x1024`.
176type ImagesResponseSize string
177
178const (
179	ImagesResponseSize1024x1024 ImagesResponseSize = "1024x1024"
180	ImagesResponseSize1024x1536 ImagesResponseSize = "1024x1536"
181	ImagesResponseSize1536x1024 ImagesResponseSize = "1536x1024"
182)
183
184// For `gpt-image-1` only, the token usage information for the image generation.
185type ImagesResponseUsage struct {
186	// The number of tokens (images and text) in the input prompt.
187	InputTokens int64 `json:"input_tokens,required"`
188	// The input tokens detailed information for the image generation.
189	InputTokensDetails ImagesResponseUsageInputTokensDetails `json:"input_tokens_details,required"`
190	// The number of image tokens in the output image.
191	OutputTokens int64 `json:"output_tokens,required"`
192	// The total number of tokens (images and text) used for the image generation.
193	TotalTokens int64 `json:"total_tokens,required"`
194	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
195	JSON struct {
196		InputTokens        respjson.Field
197		InputTokensDetails respjson.Field
198		OutputTokens       respjson.Field
199		TotalTokens        respjson.Field
200		ExtraFields        map[string]respjson.Field
201		raw                string
202	} `json:"-"`
203}
204
205// Returns the unmodified JSON received from the API
206func (r ImagesResponseUsage) RawJSON() string { return r.JSON.raw }
207func (r *ImagesResponseUsage) UnmarshalJSON(data []byte) error {
208	return apijson.UnmarshalRoot(data, r)
209}
210
211// The input tokens detailed information for the image generation.
212type ImagesResponseUsageInputTokensDetails struct {
213	// The number of image tokens in the input prompt.
214	ImageTokens int64 `json:"image_tokens,required"`
215	// The number of text tokens in the input prompt.
216	TextTokens int64 `json:"text_tokens,required"`
217	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
218	JSON struct {
219		ImageTokens respjson.Field
220		TextTokens  respjson.Field
221		ExtraFields map[string]respjson.Field
222		raw         string
223	} `json:"-"`
224}
225
226// Returns the unmodified JSON received from the API
227func (r ImagesResponseUsageInputTokensDetails) RawJSON() string { return r.JSON.raw }
228func (r *ImagesResponseUsageInputTokensDetails) UnmarshalJSON(data []byte) error {
229	return apijson.UnmarshalRoot(data, r)
230}
231
232type ImageNewVariationParams struct {
233	// The image to use as the basis for the variation(s). Must be a valid PNG file,
234	// less than 4MB, and square.
235	Image io.Reader `json:"image,omitzero,required" format:"binary"`
236	// The number of images to generate. Must be between 1 and 10.
237	N param.Opt[int64] `json:"n,omitzero"`
238	// A unique identifier representing your end-user, which can help OpenAI to monitor
239	// and detect abuse.
240	// [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#end-user-ids).
241	User param.Opt[string] `json:"user,omitzero"`
242	// The model to use for image generation. Only `dall-e-2` is supported at this
243	// time.
244	Model ImageModel `json:"model,omitzero"`
245	// The format in which the generated images are returned. Must be one of `url` or
246	// `b64_json`. URLs are only valid for 60 minutes after the image has been
247	// generated.
248	//
249	// Any of "url", "b64_json".
250	ResponseFormat ImageNewVariationParamsResponseFormat `json:"response_format,omitzero"`
251	// The size of the generated images. Must be one of `256x256`, `512x512`, or
252	// `1024x1024`.
253	//
254	// Any of "256x256", "512x512", "1024x1024".
255	Size ImageNewVariationParamsSize `json:"size,omitzero"`
256	paramObj
257}
258
259func (r ImageNewVariationParams) MarshalMultipart() (data []byte, contentType string, err error) {
260	buf := bytes.NewBuffer(nil)
261	writer := multipart.NewWriter(buf)
262	err = apiform.MarshalRoot(r, writer)
263	if err == nil {
264		err = apiform.WriteExtras(writer, r.ExtraFields())
265	}
266	if err != nil {
267		writer.Close()
268		return nil, "", err
269	}
270	err = writer.Close()
271	if err != nil {
272		return nil, "", err
273	}
274	return buf.Bytes(), writer.FormDataContentType(), nil
275}
276
277// The format in which the generated images are returned. Must be one of `url` or
278// `b64_json`. URLs are only valid for 60 minutes after the image has been
279// generated.
280type ImageNewVariationParamsResponseFormat string
281
282const (
283	ImageNewVariationParamsResponseFormatURL     ImageNewVariationParamsResponseFormat = "url"
284	ImageNewVariationParamsResponseFormatB64JSON ImageNewVariationParamsResponseFormat = "b64_json"
285)
286
287// The size of the generated images. Must be one of `256x256`, `512x512`, or
288// `1024x1024`.
289type ImageNewVariationParamsSize string
290
291const (
292	ImageNewVariationParamsSize256x256   ImageNewVariationParamsSize = "256x256"
293	ImageNewVariationParamsSize512x512   ImageNewVariationParamsSize = "512x512"
294	ImageNewVariationParamsSize1024x1024 ImageNewVariationParamsSize = "1024x1024"
295)
296
297type ImageEditParams struct {
298	// The image(s) to edit. Must be a supported image file or an array of images.
299	//
300	// For `gpt-image-1`, each image should be a `png`, `webp`, or `jpg` file less than
301	// 50MB. You can provide up to 16 images.
302	//
303	// For `dall-e-2`, you can only provide one image, and it should be a square `png`
304	// file less than 4MB.
305	Image ImageEditParamsImageUnion `json:"image,omitzero,required" format:"binary"`
306	// A text description of the desired image(s). The maximum length is 1000
307	// characters for `dall-e-2`, and 32000 characters for `gpt-image-1`.
308	Prompt string `json:"prompt,required"`
309	// The number of images to generate. Must be between 1 and 10.
310	N param.Opt[int64] `json:"n,omitzero"`
311	// The compression level (0-100%) for the generated images. This parameter is only
312	// supported for `gpt-image-1` with the `webp` or `jpeg` output formats, and
313	// defaults to 100.
314	OutputCompression param.Opt[int64] `json:"output_compression,omitzero"`
315	// A unique identifier representing your end-user, which can help OpenAI to monitor
316	// and detect abuse.
317	// [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#end-user-ids).
318	User param.Opt[string] `json:"user,omitzero"`
319	// Allows to set transparency for the background of the generated image(s). This
320	// parameter is only supported for `gpt-image-1`. Must be one of `transparent`,
321	// `opaque` or `auto` (default value). When `auto` is used, the model will
322	// automatically determine the best background for the image.
323	//
324	// If `transparent`, the output format needs to support transparency, so it should
325	// be set to either `png` (default value) or `webp`.
326	//
327	// Any of "transparent", "opaque", "auto".
328	Background ImageEditParamsBackground `json:"background,omitzero"`
329	// The model to use for image generation. Only `dall-e-2` and `gpt-image-1` are
330	// supported. Defaults to `dall-e-2` unless a parameter specific to `gpt-image-1`
331	// is used.
332	Model ImageModel `json:"model,omitzero"`
333	// The format in which the generated images are returned. This parameter is only
334	// supported for `gpt-image-1`. Must be one of `png`, `jpeg`, or `webp`. The
335	// default value is `png`.
336	//
337	// Any of "png", "jpeg", "webp".
338	OutputFormat ImageEditParamsOutputFormat `json:"output_format,omitzero"`
339	// The quality of the image that will be generated. `high`, `medium` and `low` are
340	// only supported for `gpt-image-1`. `dall-e-2` only supports `standard` quality.
341	// Defaults to `auto`.
342	//
343	// Any of "standard", "low", "medium", "high", "auto".
344	Quality ImageEditParamsQuality `json:"quality,omitzero"`
345	// The format in which the generated images are returned. Must be one of `url` or
346	// `b64_json`. URLs are only valid for 60 minutes after the image has been
347	// generated. This parameter is only supported for `dall-e-2`, as `gpt-image-1`
348	// will always return base64-encoded images.
349	//
350	// Any of "url", "b64_json".
351	ResponseFormat ImageEditParamsResponseFormat `json:"response_format,omitzero"`
352	// The size of the generated images. Must be one of `1024x1024`, `1536x1024`
353	// (landscape), `1024x1536` (portrait), or `auto` (default value) for
354	// `gpt-image-1`, and one of `256x256`, `512x512`, or `1024x1024` for `dall-e-2`.
355	//
356	// Any of "256x256", "512x512", "1024x1024", "1536x1024", "1024x1536", "auto".
357	Size ImageEditParamsSize `json:"size,omitzero"`
358	// An additional image whose fully transparent areas (e.g. where alpha is zero)
359	// indicate where `image` should be edited. If there are multiple images provided,
360	// the mask will be applied on the first image. Must be a valid PNG file, less than
361	// 4MB, and have the same dimensions as `image`.
362	Mask io.Reader `json:"mask,omitzero" format:"binary"`
363	paramObj
364}
365
366func (r ImageEditParams) MarshalMultipart() (data []byte, contentType string, err error) {
367	buf := bytes.NewBuffer(nil)
368	writer := multipart.NewWriter(buf)
369	err = apiform.MarshalRoot(r, writer)
370	if err == nil {
371		err = apiform.WriteExtras(writer, r.ExtraFields())
372	}
373	if err != nil {
374		writer.Close()
375		return nil, "", err
376	}
377	err = writer.Close()
378	if err != nil {
379		return nil, "", err
380	}
381	return buf.Bytes(), writer.FormDataContentType(), nil
382}
383
384// Only one field can be non-zero.
385//
386// Use [param.IsOmitted] to confirm if a field is set.
387type ImageEditParamsImageUnion struct {
388	OfFile      io.Reader   `json:",omitzero,inline"`
389	OfFileArray []io.Reader `json:",omitzero,inline"`
390	paramUnion
391}
392
393func (u ImageEditParamsImageUnion) MarshalJSON() ([]byte, error) {
394	return param.MarshalUnion(u, u.OfFile, u.OfFileArray)
395}
396func (u *ImageEditParamsImageUnion) UnmarshalJSON(data []byte) error {
397	return apijson.UnmarshalRoot(data, u)
398}
399
400func (u *ImageEditParamsImageUnion) asAny() any {
401	if !param.IsOmitted(u.OfFile) {
402		return &u.OfFile
403	} else if !param.IsOmitted(u.OfFileArray) {
404		return &u.OfFileArray
405	}
406	return nil
407}
408
409// Allows to set transparency for the background of the generated image(s). This
410// parameter is only supported for `gpt-image-1`. Must be one of `transparent`,
411// `opaque` or `auto` (default value). When `auto` is used, the model will
412// automatically determine the best background for the image.
413//
414// If `transparent`, the output format needs to support transparency, so it should
415// be set to either `png` (default value) or `webp`.
416type ImageEditParamsBackground string
417
418const (
419	ImageEditParamsBackgroundTransparent ImageEditParamsBackground = "transparent"
420	ImageEditParamsBackgroundOpaque      ImageEditParamsBackground = "opaque"
421	ImageEditParamsBackgroundAuto        ImageEditParamsBackground = "auto"
422)
423
424// The format in which the generated images are returned. This parameter is only
425// supported for `gpt-image-1`. Must be one of `png`, `jpeg`, or `webp`. The
426// default value is `png`.
427type ImageEditParamsOutputFormat string
428
429const (
430	ImageEditParamsOutputFormatPNG  ImageEditParamsOutputFormat = "png"
431	ImageEditParamsOutputFormatJPEG ImageEditParamsOutputFormat = "jpeg"
432	ImageEditParamsOutputFormatWebP ImageEditParamsOutputFormat = "webp"
433)
434
435// The quality of the image that will be generated. `high`, `medium` and `low` are
436// only supported for `gpt-image-1`. `dall-e-2` only supports `standard` quality.
437// Defaults to `auto`.
438type ImageEditParamsQuality string
439
440const (
441	ImageEditParamsQualityStandard ImageEditParamsQuality = "standard"
442	ImageEditParamsQualityLow      ImageEditParamsQuality = "low"
443	ImageEditParamsQualityMedium   ImageEditParamsQuality = "medium"
444	ImageEditParamsQualityHigh     ImageEditParamsQuality = "high"
445	ImageEditParamsQualityAuto     ImageEditParamsQuality = "auto"
446)
447
448// The format in which the generated images are returned. Must be one of `url` or
449// `b64_json`. URLs are only valid for 60 minutes after the image has been
450// generated. This parameter is only supported for `dall-e-2`, as `gpt-image-1`
451// will always return base64-encoded images.
452type ImageEditParamsResponseFormat string
453
454const (
455	ImageEditParamsResponseFormatURL     ImageEditParamsResponseFormat = "url"
456	ImageEditParamsResponseFormatB64JSON ImageEditParamsResponseFormat = "b64_json"
457)
458
459// The size of the generated images. Must be one of `1024x1024`, `1536x1024`
460// (landscape), `1024x1536` (portrait), or `auto` (default value) for
461// `gpt-image-1`, and one of `256x256`, `512x512`, or `1024x1024` for `dall-e-2`.
462type ImageEditParamsSize string
463
464const (
465	ImageEditParamsSize256x256   ImageEditParamsSize = "256x256"
466	ImageEditParamsSize512x512   ImageEditParamsSize = "512x512"
467	ImageEditParamsSize1024x1024 ImageEditParamsSize = "1024x1024"
468	ImageEditParamsSize1536x1024 ImageEditParamsSize = "1536x1024"
469	ImageEditParamsSize1024x1536 ImageEditParamsSize = "1024x1536"
470	ImageEditParamsSizeAuto      ImageEditParamsSize = "auto"
471)
472
473type ImageGenerateParams struct {
474	// A text description of the desired image(s). The maximum length is 32000
475	// characters for `gpt-image-1`, 1000 characters for `dall-e-2` and 4000 characters
476	// for `dall-e-3`.
477	Prompt string `json:"prompt,required"`
478	// The number of images to generate. Must be between 1 and 10. For `dall-e-3`, only
479	// `n=1` is supported.
480	N param.Opt[int64] `json:"n,omitzero"`
481	// The compression level (0-100%) for the generated images. This parameter is only
482	// supported for `gpt-image-1` with the `webp` or `jpeg` output formats, and
483	// defaults to 100.
484	OutputCompression param.Opt[int64] `json:"output_compression,omitzero"`
485	// A unique identifier representing your end-user, which can help OpenAI to monitor
486	// and detect abuse.
487	// [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#end-user-ids).
488	User param.Opt[string] `json:"user,omitzero"`
489	// Allows to set transparency for the background of the generated image(s). This
490	// parameter is only supported for `gpt-image-1`. Must be one of `transparent`,
491	// `opaque` or `auto` (default value). When `auto` is used, the model will
492	// automatically determine the best background for the image.
493	//
494	// If `transparent`, the output format needs to support transparency, so it should
495	// be set to either `png` (default value) or `webp`.
496	//
497	// Any of "transparent", "opaque", "auto".
498	Background ImageGenerateParamsBackground `json:"background,omitzero"`
499	// The model to use for image generation. One of `dall-e-2`, `dall-e-3`, or
500	// `gpt-image-1`. Defaults to `dall-e-2` unless a parameter specific to
501	// `gpt-image-1` is used.
502	Model ImageModel `json:"model,omitzero"`
503	// Control the content-moderation level for images generated by `gpt-image-1`. Must
504	// be either `low` for less restrictive filtering or `auto` (default value).
505	//
506	// Any of "low", "auto".
507	Moderation ImageGenerateParamsModeration `json:"moderation,omitzero"`
508	// The format in which the generated images are returned. This parameter is only
509	// supported for `gpt-image-1`. Must be one of `png`, `jpeg`, or `webp`.
510	//
511	// Any of "png", "jpeg", "webp".
512	OutputFormat ImageGenerateParamsOutputFormat `json:"output_format,omitzero"`
513	// The quality of the image that will be generated.
514	//
515	//   - `auto` (default value) will automatically select the best quality for the
516	//     given model.
517	//   - `high`, `medium` and `low` are supported for `gpt-image-1`.
518	//   - `hd` and `standard` are supported for `dall-e-3`.
519	//   - `standard` is the only option for `dall-e-2`.
520	//
521	// Any of "standard", "hd", "low", "medium", "high", "auto".
522	Quality ImageGenerateParamsQuality `json:"quality,omitzero"`
523	// The format in which generated images with `dall-e-2` and `dall-e-3` are
524	// returned. Must be one of `url` or `b64_json`. URLs are only valid for 60 minutes
525	// after the image has been generated. This parameter isn't supported for
526	// `gpt-image-1` which will always return base64-encoded images.
527	//
528	// Any of "url", "b64_json".
529	ResponseFormat ImageGenerateParamsResponseFormat `json:"response_format,omitzero"`
530	// The size of the generated images. Must be one of `1024x1024`, `1536x1024`
531	// (landscape), `1024x1536` (portrait), or `auto` (default value) for
532	// `gpt-image-1`, one of `256x256`, `512x512`, or `1024x1024` for `dall-e-2`, and
533	// one of `1024x1024`, `1792x1024`, or `1024x1792` for `dall-e-3`.
534	//
535	// Any of "auto", "1024x1024", "1536x1024", "1024x1536", "256x256", "512x512",
536	// "1792x1024", "1024x1792".
537	Size ImageGenerateParamsSize `json:"size,omitzero"`
538	// The style of the generated images. This parameter is only supported for
539	// `dall-e-3`. Must be one of `vivid` or `natural`. Vivid causes the model to lean
540	// towards generating hyper-real and dramatic images. Natural causes the model to
541	// produce more natural, less hyper-real looking images.
542	//
543	// Any of "vivid", "natural".
544	Style ImageGenerateParamsStyle `json:"style,omitzero"`
545	paramObj
546}
547
548func (r ImageGenerateParams) MarshalJSON() (data []byte, err error) {
549	type shadow ImageGenerateParams
550	return param.MarshalObject(r, (*shadow)(&r))
551}
552func (r *ImageGenerateParams) UnmarshalJSON(data []byte) error {
553	return apijson.UnmarshalRoot(data, r)
554}
555
556// Allows to set transparency for the background of the generated image(s). This
557// parameter is only supported for `gpt-image-1`. Must be one of `transparent`,
558// `opaque` or `auto` (default value). When `auto` is used, the model will
559// automatically determine the best background for the image.
560//
561// If `transparent`, the output format needs to support transparency, so it should
562// be set to either `png` (default value) or `webp`.
563type ImageGenerateParamsBackground string
564
565const (
566	ImageGenerateParamsBackgroundTransparent ImageGenerateParamsBackground = "transparent"
567	ImageGenerateParamsBackgroundOpaque      ImageGenerateParamsBackground = "opaque"
568	ImageGenerateParamsBackgroundAuto        ImageGenerateParamsBackground = "auto"
569)
570
571// Control the content-moderation level for images generated by `gpt-image-1`. Must
572// be either `low` for less restrictive filtering or `auto` (default value).
573type ImageGenerateParamsModeration string
574
575const (
576	ImageGenerateParamsModerationLow  ImageGenerateParamsModeration = "low"
577	ImageGenerateParamsModerationAuto ImageGenerateParamsModeration = "auto"
578)
579
580// The format in which the generated images are returned. This parameter is only
581// supported for `gpt-image-1`. Must be one of `png`, `jpeg`, or `webp`.
582type ImageGenerateParamsOutputFormat string
583
584const (
585	ImageGenerateParamsOutputFormatPNG  ImageGenerateParamsOutputFormat = "png"
586	ImageGenerateParamsOutputFormatJPEG ImageGenerateParamsOutputFormat = "jpeg"
587	ImageGenerateParamsOutputFormatWebP ImageGenerateParamsOutputFormat = "webp"
588)
589
590// The quality of the image that will be generated.
591//
592//   - `auto` (default value) will automatically select the best quality for the
593//     given model.
594//   - `high`, `medium` and `low` are supported for `gpt-image-1`.
595//   - `hd` and `standard` are supported for `dall-e-3`.
596//   - `standard` is the only option for `dall-e-2`.
597type ImageGenerateParamsQuality string
598
599const (
600	ImageGenerateParamsQualityStandard ImageGenerateParamsQuality = "standard"
601	ImageGenerateParamsQualityHD       ImageGenerateParamsQuality = "hd"
602	ImageGenerateParamsQualityLow      ImageGenerateParamsQuality = "low"
603	ImageGenerateParamsQualityMedium   ImageGenerateParamsQuality = "medium"
604	ImageGenerateParamsQualityHigh     ImageGenerateParamsQuality = "high"
605	ImageGenerateParamsQualityAuto     ImageGenerateParamsQuality = "auto"
606)
607
608// The format in which generated images with `dall-e-2` and `dall-e-3` are
609// returned. Must be one of `url` or `b64_json`. URLs are only valid for 60 minutes
610// after the image has been generated. This parameter isn't supported for
611// `gpt-image-1` which will always return base64-encoded images.
612type ImageGenerateParamsResponseFormat string
613
614const (
615	ImageGenerateParamsResponseFormatURL     ImageGenerateParamsResponseFormat = "url"
616	ImageGenerateParamsResponseFormatB64JSON ImageGenerateParamsResponseFormat = "b64_json"
617)
618
619// The size of the generated images. Must be one of `1024x1024`, `1536x1024`
620// (landscape), `1024x1536` (portrait), or `auto` (default value) for
621// `gpt-image-1`, one of `256x256`, `512x512`, or `1024x1024` for `dall-e-2`, and
622// one of `1024x1024`, `1792x1024`, or `1024x1792` for `dall-e-3`.
623type ImageGenerateParamsSize string
624
625const (
626	ImageGenerateParamsSizeAuto      ImageGenerateParamsSize = "auto"
627	ImageGenerateParamsSize1024x1024 ImageGenerateParamsSize = "1024x1024"
628	ImageGenerateParamsSize1536x1024 ImageGenerateParamsSize = "1536x1024"
629	ImageGenerateParamsSize1024x1536 ImageGenerateParamsSize = "1024x1536"
630	ImageGenerateParamsSize256x256   ImageGenerateParamsSize = "256x256"
631	ImageGenerateParamsSize512x512   ImageGenerateParamsSize = "512x512"
632	ImageGenerateParamsSize1792x1024 ImageGenerateParamsSize = "1792x1024"
633	ImageGenerateParamsSize1024x1792 ImageGenerateParamsSize = "1024x1792"
634)
635
636// The style of the generated images. This parameter is only supported for
637// `dall-e-3`. Must be one of `vivid` or `natural`. Vivid causes the model to lean
638// towards generating hyper-real and dramatic images. Natural causes the model to
639// produce more natural, less hyper-real looking images.
640type ImageGenerateParamsStyle string
641
642const (
643	ImageGenerateParamsStyleVivid   ImageGenerateParamsStyle = "vivid"
644	ImageGenerateParamsStyleNatural ImageGenerateParamsStyle = "natural"
645)