Creates an image given a prompt. [Learn more](https://platform.openai.com/docs/guides/images). Args: prompt: A text description of the desired image(s). The maximum length is 32000 characters for the GPT image models, 1000 characters for `dall-e-2` a
(
self,
*,
prompt: str,
background: Optional[Literal["transparent", "opaque", "auto"]] | Omit = omit,
model: Union[str, ImageModel, None] | Omit = omit,
moderation: Optional[Literal["low", "auto"]] | Omit = omit,
n: Optional[int] | Omit = omit,
output_compression: Optional[int] | Omit = omit,
output_format: Optional[Literal["png", "jpeg", "webp"]] | Omit = omit,
partial_images: Optional[int] | Omit = omit,
quality: Optional[Literal["standard", "hd", "low", "medium", "high", "auto"]] | Omit = omit,
response_format: Optional[Literal["url", "b64_json"]] | Omit = omit,
size: Union[
str,
Literal["auto", "1024x1024", "1536x1024", "1024x1536", "256x256", "512x512", "1792x1024", "1024x1792"],
None,
]
| Omit = omit,
stream: Optional[Literal[False]] | Omit = omit,
style: Optional[Literal["vivid", "natural"]] | Omit = omit,
user: str | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
)
| 1593 | |
| 1594 | @overload |
| 1595 | async def generate( |
| 1596 | self, |
| 1597 | *, |
| 1598 | prompt: str, |
| 1599 | background: Optional[Literal["transparent", "opaque", "auto"]] | Omit = omit, |
| 1600 | model: Union[str, ImageModel, None] | Omit = omit, |
| 1601 | moderation: Optional[Literal["low", "auto"]] | Omit = omit, |
| 1602 | n: Optional[int] | Omit = omit, |
| 1603 | output_compression: Optional[int] | Omit = omit, |
| 1604 | output_format: Optional[Literal["png", "jpeg", "webp"]] | Omit = omit, |
| 1605 | partial_images: Optional[int] | Omit = omit, |
| 1606 | quality: Optional[Literal["standard", "hd", "low", "medium", "high", "auto"]] | Omit = omit, |
| 1607 | response_format: Optional[Literal["url", "b64_json"]] | Omit = omit, |
| 1608 | size: Union[ |
| 1609 | str, |
| 1610 | Literal["auto", "1024x1024", "1536x1024", "1024x1536", "256x256", "512x512", "1792x1024", "1024x1792"], |
| 1611 | None, |
| 1612 | ] |
| 1613 | | Omit = omit, |
| 1614 | stream: Optional[Literal[False]] | Omit = omit, |
| 1615 | style: Optional[Literal["vivid", "natural"]] | Omit = omit, |
| 1616 | user: str | Omit = omit, |
| 1617 | # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 1618 | # The extra values given here take precedence over values defined on the client or passed to this method. |
| 1619 | extra_headers: Headers | None = None, |
| 1620 | extra_query: Query | None = None, |
| 1621 | extra_body: Body | None = None, |
| 1622 | timeout: float | httpx.Timeout | None | NotGiven = not_given, |
| 1623 | ) -> ImagesResponse: |
| 1624 | """ |
| 1625 | Creates an image given a prompt. |
| 1626 | [Learn more](https://platform.openai.com/docs/guides/images). |
| 1627 | |
| 1628 | Args: |
| 1629 | prompt: A text description of the desired image(s). The maximum length is 32000 |
| 1630 | characters for the GPT image models, 1000 characters for `dall-e-2` and 4000 |
| 1631 | characters for `dall-e-3`. |
| 1632 | |
| 1633 | background: Allows to set transparency for the background of the generated image(s). This |
| 1634 | parameter is only supported for GPT image models that support transparent |
| 1635 | backgrounds. Must be one of `transparent`, `opaque`, or `auto` (default value). |
| 1636 | When `auto` is used, the model will automatically determine the best background |
| 1637 | for the image. |
| 1638 | |
| 1639 | `gpt-image-2` and `gpt-image-2-2026-04-21` do not support transparent |
| 1640 | backgrounds. Requests with `background` set to `transparent` will return an |
| 1641 | error for these models; use `opaque` or `auto` instead. |
| 1642 | |
| 1643 | If `transparent`, the output format needs to support transparency, so it should |
| 1644 | be set to either `png` (default value) or `webp`. |
| 1645 | |
| 1646 | model: The model to use for image generation. One of `dall-e-2`, `dall-e-3`, or a GPT |
| 1647 | image model (`gpt-image-1`, `gpt-image-1-mini`, `gpt-image-1.5`, `gpt-image-2`, |
| 1648 | or `gpt-image-2-2026-04-21`). Defaults to `dall-e-2` unless a parameter specific |
| 1649 | to the GPT image models is used. |
| 1650 | |
| 1651 | moderation: Control the content-moderation level for images generated by the GPT image |
| 1652 | models. Must be either `low` for less restrictive filtering or `auto` (default |
nothing calls this directly
no test coverage detected