feat(images): support ImageInputReferenceParam in images.edit()#3259
feat(images): support ImageInputReferenceParam in images.edit()#3259JiwaniZakir wants to merge 1 commit into
Conversation
Allow passing an ImageInputReferenceParam (with file_id or image_url) as the image argument to images.edit(), in addition to file uploads. When a URL/reference input is detected, skip multipart encoding and send JSON instead. Closes openai#3256
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4029d39731
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| extra_body: Body | None = None, | ||
| timeout: float | httpx.Timeout | None | NotGiven = not_given, | ||
| ) -> ImagesResponse | Stream[ImageEditStreamEvent]: | ||
| is_url_input = is_mapping(image) or (is_list(image) and len(image) > 0 and is_mapping(image[0])) |
There was a problem hiding this comment.
Send image references under the JSON
images field
When image is a reference dict/list this branch switches the request to application/json, but the body constructed below still uses the multipart-only image key. The image edit JSON API expects images as an array of {image_url|file_id} references, so client.images.edit(image={"image_url": ...}, ...) posts the wrong payload and the new reference-input path is rejected instead of working. Please translate reference inputs to the images field, wrapping a single reference in an array, when taking this JSON path.
Useful? React with 👍 / 👎.
The images.edit() endpoint only accepted file uploads for the image parameter, but the API also supports passing an image reference (file_id or image_url) via ImageInputReferenceParam. Callers passing a reference dict would get a multipart/form-data encoding error instead of a JSON request.
Added ImageInputReferenceParam to the accepted union type for the image parameter in both Images and AsyncImages, and added detection logic so that reference inputs bypass multipart encoding and are sent as JSON instead.
To verify, call client.images.edit(image={"image_url": "https://..."}, prompt="...") and confirm it sends a JSON body rather than failing with a multipart error.
Fixes #3256