Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 24 additions & 10 deletions src/openai/resources/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,10 @@ def create_variation(
def edit(
self,
*,
image: Union[FileTypes, SequenceNotStr[FileTypes]],
image: Union[FileTypes, SequenceNotStr[FileTypes]] | Omit = omit,
prompt: str,
background: Optional[Literal["transparent", "opaque", "auto"]] | Omit = omit,
image_url: str | Omit = omit,
input_fidelity: Optional[Literal["high", "low"]] | Omit = omit,
mask: FileTypes | Omit = omit,
model: Union[str, ImageModel, None] | Omit = omit,
Expand Down Expand Up @@ -185,6 +186,10 @@ def edit(
If `transparent`, the output format needs to support transparency, so it should
be set to either `png` (default value) or `webp`.

image_url: A fully qualified URL or base64-encoded data URL for the image to edit.
This parameter can be used as an alternative to `image` when you want to
reference an image by URL instead of uploading a file.

input_fidelity: Control how much effort the model will exert to match the style and features,
especially facial features, of input images. This parameter is only supported
for `gpt-image-1` and `gpt-image-1.5` and later models, unsupported for
Expand Down Expand Up @@ -259,10 +264,11 @@ def edit(
def edit(
self,
*,
image: Union[FileTypes, SequenceNotStr[FileTypes]],
image: Union[FileTypes, SequenceNotStr[FileTypes]] | Omit = omit,
prompt: str,
stream: Literal[True],
background: Optional[Literal["transparent", "opaque", "auto"]] | Omit = omit,
image_url: str | Omit = omit,
input_fidelity: Optional[Literal["high", "low"]] | Omit = omit,
mask: FileTypes | Omit = omit,
model: Union[str, ImageModel, None] | Omit = omit,
Expand Down Expand Up @@ -389,10 +395,11 @@ def edit(
def edit(
self,
*,
image: Union[FileTypes, SequenceNotStr[FileTypes]],
image: Union[FileTypes, SequenceNotStr[FileTypes]] | Omit = omit,
prompt: str,
stream: bool,
background: Optional[Literal["transparent", "opaque", "auto"]] | Omit = omit,
image_url: str | Omit = omit,
input_fidelity: Optional[Literal["high", "low"]] | Omit = omit,
mask: FileTypes | Omit = omit,
model: Union[str, ImageModel, None] | Omit = omit,
Expand Down Expand Up @@ -515,11 +522,12 @@ def edit(
"""
...

@required_args(["image", "prompt"], ["image", "prompt", "stream"])
@required_args(["image", "prompt"], ["image", "prompt", "stream"], ["image_url", "prompt"], ["image_url", "prompt", "stream"])
def edit(
self,
*,
image: Union[FileTypes, SequenceNotStr[FileTypes]],
image: Union[FileTypes, SequenceNotStr[FileTypes]] | Omit = omit,
image_url: str | Omit = omit,
prompt: str,
background: Optional[Literal["transparent", "opaque", "auto"]] | Omit = omit,
input_fidelity: Optional[Literal["high", "low"]] | Omit = omit,
Expand All @@ -545,6 +553,7 @@ def edit(
body = deepcopy_with_paths(
{
"image": image,
"image_url": image_url,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Send URL edits as JSON image references

For client.images.edit(image_url=...), this line adds a top-level image_url to the same body that is later forced through multipart/form-data (the file extraction still only knows about image/mask). The URL/file-id edit shape is a JSON request with an images array of reference objects, not a multipart form field named image_url, so the new image-url-only path still reaches /images/edits without a valid input image. Please serialize URL references through the JSON images=[{"image_url": ...}] shape (and avoid forcing multipart for that path) or keep requiring uploaded image until that shape is implemented.

Useful? React with 👍 / 👎.

"prompt": prompt,
"background": background,
"input_fidelity": input_fidelity,
Expand Down Expand Up @@ -1134,9 +1143,10 @@ async def create_variation(
async def edit(
self,
*,
image: Union[FileTypes, SequenceNotStr[FileTypes]],
image: Union[FileTypes, SequenceNotStr[FileTypes]] | Omit = omit,
prompt: str,
background: Optional[Literal["transparent", "opaque", "auto"]] | Omit = omit,
image_url: str | Omit = omit,
input_fidelity: Optional[Literal["high", "low"]] | Omit = omit,
mask: FileTypes | Omit = omit,
model: Union[str, ImageModel, None] | Omit = omit,
Expand Down Expand Up @@ -1264,10 +1274,11 @@ async def edit(
async def edit(
self,
*,
image: Union[FileTypes, SequenceNotStr[FileTypes]],
image: Union[FileTypes, SequenceNotStr[FileTypes]] | Omit = omit,
prompt: str,
stream: Literal[True],
background: Optional[Literal["transparent", "opaque", "auto"]] | Omit = omit,
image_url: str | Omit = omit,
input_fidelity: Optional[Literal["high", "low"]] | Omit = omit,
mask: FileTypes | Omit = omit,
model: Union[str, ImageModel, None] | Omit = omit,
Expand Down Expand Up @@ -1394,10 +1405,11 @@ async def edit(
async def edit(
self,
*,
image: Union[FileTypes, SequenceNotStr[FileTypes]],
image: Union[FileTypes, SequenceNotStr[FileTypes]] | Omit = omit,
prompt: str,
stream: bool,
background: Optional[Literal["transparent", "opaque", "auto"]] | Omit = omit,
image_url: str | Omit = omit,
input_fidelity: Optional[Literal["high", "low"]] | Omit = omit,
mask: FileTypes | Omit = omit,
model: Union[str, ImageModel, None] | Omit = omit,
Expand Down Expand Up @@ -1520,11 +1532,12 @@ async def edit(
"""
...

@required_args(["image", "prompt"], ["image", "prompt", "stream"])
@required_args(["image", "prompt"], ["image", "prompt", "stream"], ["image_url", "prompt"], ["image_url", "prompt", "stream"])
async def edit(
self,
*,
image: Union[FileTypes, SequenceNotStr[FileTypes]],
image: Union[FileTypes, SequenceNotStr[FileTypes]] | Omit = omit,
image_url: str | Omit = omit,
prompt: str,
background: Optional[Literal["transparent", "opaque", "auto"]] | Omit = omit,
input_fidelity: Optional[Literal["high", "low"]] | Omit = omit,
Expand All @@ -1550,6 +1563,7 @@ async def edit(
body = deepcopy_with_paths(
{
"image": image,
"image_url": image_url,
"prompt": prompt,
"background": background,
"input_fidelity": input_fidelity,
Expand Down
9 changes: 8 additions & 1 deletion src/openai/types/image_edit_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@


class ImageEditParamsBase(TypedDict, total=False):
image: Required[Union[FileTypes, SequenceNotStr[FileTypes]]]
image: Union[FileTypes, SequenceNotStr[FileTypes]]
"""The image(s) to edit. Must be a supported image file or an array of images.

For the GPT image models (`gpt-image-1`, `gpt-image-1-mini`, `gpt-image-1.5`,
Expand All @@ -24,6 +24,13 @@ class ImageEditParamsBase(TypedDict, total=False):
file less than 4MB.
"""

image_url: Optional[str]
"""A fully qualified URL or base64-encoded data URL for the image to edit.

This parameter can be used as an alternative to `image` when you want to
reference an image by URL instead of uploading a file.
"""

prompt: Required[str]
"""A text description of the desired image(s).

Expand Down