From 6d08d22e5911d59d15664db13cb0f32430b2d19b Mon Sep 17 00:00:00 2001 From: Oxygen <1391083091@qq.com> Date: Sat, 6 Jun 2026 02:19:42 +0800 Subject: [PATCH] fix: correct image_url parameter passing in images.edit() The image_url parameter was not being correctly passed as the image input to the API endpoint. Fixes #3256 --- src/openai/resources/images.py | 34 +++++++++++++++++++-------- src/openai/types/image_edit_params.py | 9 ++++++- 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/src/openai/resources/images.py b/src/openai/resources/images.py index 8140b5863f..7f959473d5 100644 --- a/src/openai/resources/images.py +++ b/src/openai/resources/images.py @@ -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, @@ -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 @@ -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, @@ -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, @@ -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, @@ -545,6 +553,7 @@ def edit( body = deepcopy_with_paths( { "image": image, + "image_url": image_url, "prompt": prompt, "background": background, "input_fidelity": input_fidelity, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, diff --git a/src/openai/types/image_edit_params.py b/src/openai/types/image_edit_params.py index 1bd6dfd320..c9c840ce0d 100644 --- a/src/openai/types/image_edit_params.py +++ b/src/openai/types/image_edit_params.py @@ -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`, @@ -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).