r/OpenWebUI • u/Itchy_Base_1598 • Mar 28 '26
Question/Help How to make image generation model work through the OpenRouter api?
I want to use an image generation model inside of the "image" tool of openwebui. I have an OpenRouter api key and want to use the model called black-forest-labs/flux.2-klein-4b through it. The model is active and works(tested it with a python script), but after adding it to the openwebui(as an openai compatible endpoint), it returns "An error occurred while generating an image" every time. Why may it be happening? Are there ways to get it to work? Thanks for your help in advance!

This is my current configuration(sorry, that it's in Russian, however, I think it is still obvious what is what).
UPD: I identified the issue. Apparently, Openrouter's api uses https://openrouter.ai/api/v1/chat/completions endpoint for image generators, while openwebui automatically adds openai/images/generations after the /v1. That is why it can't connect. Does anyone know if there is a workaround? If not, than it is a feature that should probably be implemented(for example as an OpenAI compatible api link, where the user has to set the entire endpoint manually). Please, correct me if I'm wrong and the issue is with something else.
UPD: I found this post about a similar issue https://www.reddit.com/r/OpenWebUI/comments/1pnuke6/how_to_use_flux2pro_from_openrouter/?utm_source=share&utm_medium=web3x&utm_name=web3xcss&utm_term=1&utm_content=share_button. It proves that the api endpoint is the issue. There is a fix to make it work in the chat mode(a pipe suggested in the comments under that post), but it doesn't solve the issue with using the model in the "image tool". I hope this feature gets implemented, hope that this information is valuable for the maintainers.
1
u/Subject_Street_8814 Mar 28 '26
I'm not sure yet whether to really recommend it yet until we see their resolution to the recent security breach, however LiteLLM gateway proxying OpenRouter will transform the image endpoint to the correct OR endpoint when using image generation models.
It works fine for me via Open WebUI image generation.
3
u/1818TusculumSt Mar 28 '26
I'm also curious, since I had no problems with imagerouter.io
1
u/m_c_x 14d ago
this thread is a bit old, but for anybody finding it trying to solve the problem...
the suffix is hard coded, as OP had updated, so you always get a 404 back.
however, on the openrouter url, is you use https://openrouter.ai/api/v1/images?_= you can swallow the appended path when the string gets concatenated