feat: add OpenRouter provider support - #5
Conversation
Add support for OpenRouter's OpenAI-compatible API as an alternative to the direct Google Gemini SDK. This allows using any model available on OpenRouter (Gemini, Claude, GPT, etc.) for both text planning and image generation via a single OPENROUTER_API_KEY. New providers: - openrouter (VLM): text generation via /chat/completions - openrouter_imagen (ImageGen): image generation via modalities param Usage: --vlm-provider openrouter --vlm-model google/gemini-2.0-flash-001 --image-provider openrouter_imagen --image-model google/gemini-3-pro-image-preview
|
|
||
| from __future__ import annotations | ||
|
|
||
| import re |
There was a problem hiding this comment.
Unused import
reisn't used anywhere in this file (it's used in the image gen provider but not here). This will failruffcheck with F401.
| if self._client is None: | ||
| import httpx | ||
|
|
||
| self._client = httpx.Client( |
There was a problem hiding this comment.
Non-blocking suggestion: since generate() is an async method and httpx has a native async API, it would be cleaner to use httpx.AsyncClient with await client.post(...) here and in the image gen provider. The current synchronous client works but will block the event loop during requests. Not a hard requirement since the existing Gemini providers also use synchronous SDK calls inside async methods, but httpx makes async easy so it would be a nice improvement.
dippatel1994
left a comment
There was a problem hiding this comment.
Thanks for the contribution, Fabian! This is a clean addition, and the provider pattern looks good.
Minor corrections (if you can address them, that would be great):
- Unused import re in the VLM provider (will fail ruff).
- Consider using httpx.AsyncClient since httpx has native async support (optional but recommended).
Happy to merge once the unused import is removed. Thanks again @nicremo!
Address PR review feedback: - Remove unused `import re` from VLM provider (F401) - Switch both OpenRouter providers from httpx.Client to httpx.AsyncClient to avoid blocking the event loop
|
Thank you for the feedback! Really happy you like the addition 😊 Just pushed both fixes:
Let me know if there's anything else! |
|
Thanks for the contribution and for the quick fixes! |
Summary
Added OpenRouter as an alternative provider for both VLM and image generation. Needed this for myself since the Google free tier quota runs out pretty quickly — OpenRouter lets you use the same models (Gemini, etc.) with a single API key.
What's new:
openrouterVLM provider (text generation via OpenRouter's OpenAI-compatible API)openrouter_imagenimage generation provider (usesmodalities: ["image", "text"])OPENROUTER_API_KEYconfig field in SettingsUsage:
No changes to existing Gemini providers — purely additive.