Skip to content

fix(openai): use edits endpoint for image-to-image - #328

Merged
xxynet merged 2 commits into
devfrom
fix/openai-image-edits
Sep 23, 2026
Merged

xxynet merged 2 commits into
devfrom
fix/openai-image-edits

Conversation

@xxynet

@xxynet xxynet commented Sep 23, 2026 •

Copy link
Copy Markdown
Owner

Summary

Use the OpenAI Images edits endpoint for image-to-image requests made through the v1/image mode, and support the Base64 image responses returned by GPT Image models for both generation and editing. Previously, reference images were passed through the generations endpoint and both paths assumed a URL response.

Type of change

  • feat: New feature
  • fix: Bug fix
  • refactor: Code refactor (no functional change)
  • docs: Documentation update
  • chore: Build, CI, dependencies, or other maintenance
  • style: Code style / formatting (no logic change)
  • test: Adding or updating tests

Changes

  • Route v1/image image-to-image calls through client.images.edit.
  • Parse both url and b64_json results for image generation and editing.
  • Stop forcing the unsupported GPT Image response_format parameter and remove the non-standard watermark request field.
  • Convert Base64 image Data URLs into validated multipart upload values for PNG, JPEG, and WebP inputs.
  • Preserve single-image and multi-image editing support.
  • Keep the v1/chat image flows unchanged.
  • Add regression coverage for Base64 and URL responses, multi-image uploads, MIME handling, invalid Data URLs, empty responses, and empty edit inputs.

Screenshots / Logs

Not applicable (backend-only change).

Validation:

python -m pytest tests/test_openai_image_client.py tests/test_openai_request_kwargs.py tests/test_openai_stt_client.py tests/test_openai_tts_client.py -v
20 passed in 0.95s

Checklist

  • I have tested these changes locally
  • I have updated documentation if needed
  • New dependencies have been added to requirements.txt (if applicable)
  • If this PR introduces new features, they have been discussed with the owner or maintainer
  • This PR does not introduce breaking changes

Summary by CodeRabbit

  • New Features
    • Image editing now supports image uploads alongside a prompt.
    • Image generation and editing handle image results consistently, including URL and Base64 data.
  • Bug Fixes
    • Invalid or unsupported image inputs, missing image data, and responses without usable images now produce clear validation errors. Editing requests without input images no longer call the image service.

@coderabbitai

coderabbitai Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: b04f8efb-b3c9-45a7-9d6f-a4fffa29c2fc

📥 Commits

Reviewing files that changed from the base of the PR and between 5dc39e9 and 8590019.

📒 Files selected for processing (2)
  • core/provider/src/openai/model_clients.py
  • tests/test_openai_image_client.py

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The OpenAI image client now parses URL or Base64 responses. Text-to-image requests use the generations endpoint, while image-to-image requests use the edits endpoint with validated image file uploads.

Changes

OpenAI image requests

Layer / File(s) Summary
Image data parsing and validation
core/provider/src/openai/model_clients.py, tests/test_openai_image_client.py
The client parses URL or Base64 image responses and converts supported Base64 Data URLs into upload tuples. Tests check invalid Data URLs and missing response data.
Generation and editing API paths
core/provider/src/openai/model_clients.py, tests/test_openai_image_client.py
Text-to-image requests use images.generate without forced response-format or watermark parameters. Image-to-image requests use images.edit with validated upload tuples and reject empty input. Tests cover both request paths.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 85900

Image generation and editing response paths preserve usable image data; no merge-blocking risk remains.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 18 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: routing image-to-image requests through the OpenAI edits endpoint.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

A rabbit packs a PNG with care,
Then sends it through the edits’ lair.
A Base64 picture finds its way,
A URL may answer back today.
The bunny checks each file it sends,
And hops through images to the end.

Comment @coderabbitai help to get the list of available commands.

@xxynet
xxynet merged commit 96dac49 into dev Sep 23, 2026
4 checks passed
@xxynet
xxynet deleted the fix/openai-image-edits branch September 23, 2026 11:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant