main
1# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
3from __future__ import annotations
4
5from typing import Union, Optional
6from typing_extensions import Literal, Required, TypedDict
7
8from .image_model import ImageModel
9
10__all__ = ["ImageGenerateParamsBase", "ImageGenerateParamsNonStreaming", "ImageGenerateParamsStreaming"]
11
12
13class ImageGenerateParamsBase(TypedDict, total=False):
14 prompt: Required[str]
15 """A text description of the desired image(s).
16
17 The maximum length is 32000 characters for `gpt-image-1`, 1000 characters for
18 `dall-e-2` and 4000 characters for `dall-e-3`.
19 """
20
21 background: Optional[Literal["transparent", "opaque", "auto"]]
22 """
23 Allows to set transparency for the background of the generated image(s). This
24 parameter is only supported for `gpt-image-1`. Must be one of `transparent`,
25 `opaque` or `auto` (default value). When `auto` is used, the model will
26 automatically determine the best background for the image.
27
28 If `transparent`, the output format needs to support transparency, so it should
29 be set to either `png` (default value) or `webp`.
30 """
31
32 model: Union[str, ImageModel, None]
33 """The model to use for image generation.
34
35 One of `dall-e-2`, `dall-e-3`, or `gpt-image-1`. Defaults to `dall-e-2` unless a
36 parameter specific to `gpt-image-1` is used.
37 """
38
39 moderation: Optional[Literal["low", "auto"]]
40 """Control the content-moderation level for images generated by `gpt-image-1`.
41
42 Must be either `low` for less restrictive filtering or `auto` (default value).
43 """
44
45 n: Optional[int]
46 """The number of images to generate.
47
48 Must be between 1 and 10. For `dall-e-3`, only `n=1` is supported.
49 """
50
51 output_compression: Optional[int]
52 """The compression level (0-100%) for the generated images.
53
54 This parameter is only supported for `gpt-image-1` with the `webp` or `jpeg`
55 output formats, and defaults to 100.
56 """
57
58 output_format: Optional[Literal["png", "jpeg", "webp"]]
59 """The format in which the generated images are returned.
60
61 This parameter is only supported for `gpt-image-1`. Must be one of `png`,
62 `jpeg`, or `webp`.
63 """
64
65 partial_images: Optional[int]
66 """The number of partial images to generate.
67
68 This parameter is used for streaming responses that return partial images. Value
69 must be between 0 and 3. When set to 0, the response will be a single image sent
70 in one streaming event.
71
72 Note that the final image may be sent before the full number of partial images
73 are generated if the full image is generated more quickly.
74 """
75
76 quality: Optional[Literal["standard", "hd", "low", "medium", "high", "auto"]]
77 """The quality of the image that will be generated.
78
79 - `auto` (default value) will automatically select the best quality for the
80 given model.
81 - `high`, `medium` and `low` are supported for `gpt-image-1`.
82 - `hd` and `standard` are supported for `dall-e-3`.
83 - `standard` is the only option for `dall-e-2`.
84 """
85
86 response_format: Optional[Literal["url", "b64_json"]]
87 """The format in which generated images with `dall-e-2` and `dall-e-3` are
88 returned.
89
90 Must be one of `url` or `b64_json`. URLs are only valid for 60 minutes after the
91 image has been generated. This parameter isn't supported for `gpt-image-1` which
92 will always return base64-encoded images.
93 """
94
95 size: Optional[
96 Literal["auto", "1024x1024", "1536x1024", "1024x1536", "256x256", "512x512", "1792x1024", "1024x1792"]
97 ]
98 """The size of the generated images.
99
100 Must be one of `1024x1024`, `1536x1024` (landscape), `1024x1536` (portrait), or
101 `auto` (default value) for `gpt-image-1`, one of `256x256`, `512x512`, or
102 `1024x1024` for `dall-e-2`, and one of `1024x1024`, `1792x1024`, or `1024x1792`
103 for `dall-e-3`.
104 """
105
106 style: Optional[Literal["vivid", "natural"]]
107 """The style of the generated images.
108
109 This parameter is only supported for `dall-e-3`. Must be one of `vivid` or
110 `natural`. Vivid causes the model to lean towards generating hyper-real and
111 dramatic images. Natural causes the model to produce more natural, less
112 hyper-real looking images.
113 """
114
115 user: str
116 """
117 A unique identifier representing your end-user, which can help OpenAI to monitor
118 and detect abuse.
119 [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#end-user-ids).
120 """
121
122
123class ImageGenerateParamsNonStreaming(ImageGenerateParamsBase, total=False):
124 stream: Optional[Literal[False]]
125 """Generate the image in streaming mode.
126
127 Defaults to `false`. See the
128 [Image generation guide](https://platform.openai.com/docs/guides/image-generation)
129 for more information. This parameter is only supported for `gpt-image-1`.
130 """
131
132
133class ImageGenerateParamsStreaming(ImageGenerateParamsBase):
134 stream: Required[Literal[True]]
135 """Generate the image in streaming mode.
136
137 Defaults to `false`. See the
138 [Image generation guide](https://platform.openai.com/docs/guides/image-generation)
139 for more information. This parameter is only supported for `gpt-image-1`.
140 """
141
142
143ImageGenerateParams = Union[ImageGenerateParamsNonStreaming, ImageGenerateParamsStreaming]