Skip to content

Fix paint not working with OpenRouter provider (#513)#558

Merged
crmne merged 2 commits intocrmne:mainfrom
khasinski:fix/openrouter-paint-image-generation
Mar 1, 2026
Merged

Fix paint not working with OpenRouter provider (#513)#558
crmne merged 2 commits intocrmne:mainfrom
khasinski:fix/openrouter-paint-image-generation

Conversation

@khasinski
Copy link
Contributor

OpenRouter uses the chat completions endpoint for image generation instead of a dedicated /images/generations endpoint. This commit adds an OpenRouter::Images module that:

  • Routes image generation requests to chat/completions
  • Formats the payload with modalities: ["image", "text"]
  • Parses the response from choices[0].message.images[]
  • Handles both base64 data URLs and regular URLs

What this does

When using RubyLLM.paint with OpenRouter, requests were being sent to https://openrouter.ai/api/v1/images/generations, which doesn't exist. OpenRouter returns a 405 Method Not Allowed error.

OpenRouter implements image generation via the chat completions endpoint (/chat/completions) with modalities: ["image", "text"], not through a dedicated images endpoint.

This PR adds an OpenRouter::Images module that overrides the inherited OpenAI::Images behavior to:

  1. Route to the correct endpoint: chat/completions instead of images/generations
  2. Format the request correctly: Uses chat message format with modalities: ["image", "text"]
  3. Parse the response correctly: Extracts images from choices[0].message.images[] as base64 data URLs

Tested with google/gemini-2.5-flash-image-preview via OpenRouter.

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation
  • Performance improvement

Scope check

  • I read the Contributing Guide
  • This aligns with RubyLLM's focus on LLM communication
  • This isn't application-specific logic that belongs in user code
  • This benefits most users, not just my specific use case

Quality check

  • I ran overcommit --install and all hooks pass
  • I tested my changes thoroughly
    • For provider changes: Re-recorded VCR cassettes with bundle exec rake vcr:record[provider_name]
    • All tests pass: bundle exec rspec
  • I updated documentation if needed
  • I didn't modify auto-generated files manually (models.json, aliases.json)

API changes

  • Breaking change
  • New public methods/classes
  • Changed method signatures
  • No API changes

Related issues

Fixes #513

@khasinski khasinski force-pushed the fix/openrouter-paint-image-generation branch from 9502ce0 to b0963d3 Compare January 10, 2026 01:08
@fguillen
Copy link

Please, maintainers, take a look here, we need this! :)

OpenRouter uses the chat completions endpoint for image generation
instead of a dedicated /images/generations endpoint. This commit adds
an OpenRouter::Images module that:

- Routes image generation requests to chat/completions
- Formats the payload with modalities: ["image", "text"]
- Parses the response from choices[0].message.images[]
- Handles both base64 data URLs and regular URLs
@khasinski khasinski force-pushed the fix/openrouter-paint-image-generation branch from b0963d3 to 49a2912 Compare January 18, 2026 21:00
@khasinski
Copy link
Contributor Author

🚀 Yay!

@crmne crmne merged commit 9c78fba into crmne:main Mar 1, 2026
19 checks passed
@codecov
Copy link

codecov bot commented Mar 1, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.95%. Comparing base (90b8dd1) to head (83349b5).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #558      +/-   ##
==========================================
+ Coverage   80.85%   80.95%   +0.09%     
==========================================
  Files         113      114       +1     
  Lines        5187     5213      +26     
  Branches     1345     1351       +6     
==========================================
+ Hits         4194     4220      +26     
  Misses        993      993              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

[BUG] paint is not working with openrouter provider

3 participants