The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
feat(image-gen): route live-catalog models to the Image API; merge picker catalogs; docs
Tekniumaba96d52512c
diff --git a/plugins/image_gen/openrouter/__init__.py b/plugins/image_gen/openrouter/__init__.pyindex 56e4c6bf7a1..bb3f23e7031 100644--- a/plugins/image_gen/openrouter/__init__.py+++ b/plugins/image_gen/openrouter/__init__.py@@ -498,18 +498,17 @@ def _fetch_image_api_catalog(base_url: str, api_key: str) -> frozenset:#: rerouting them would be a silent behaviour change — see the module docstring._CHAT_ONLY_MODELS = frozenset({DEFAULT_MODEL, _FALLBACK_MODEL})-#: Ids we have already hinted about, so the log line appears once per process-#: rather than on every call.-_HINTED_MODELS: set = set()def _select_surface(model_id: str, base_url: str, api_key: str, config_key: str) -> str:"""Return ``"images"`` or ``"chat"`` for *model_id*.- Deterministic and offline in the default case: the decision comes from- :data:`_IMAGE_API_MODELS` and :data:`_CHAT_ONLY_MODELS`, never from the- network. The catalog probe runs only for an id in neither table, and only- to produce a hint — it does not change the route.+ Deterministic and offline for curated ids: the decision comes from+ :data:`_IMAGE_API_MODELS` and :data:`_CHAT_ONLY_MODELS`. An id in neither+ table is checked against the (cached) live ``/images/models`` catalog —+ models the dedicated API serves route there, so a model picked from the+ live picker works even when it postdates the curated snapshot. Offline+ the probe returns empty and unknown ids stay on chat-completions."""if not model_id:return "chat"@@ -523,19 +522,11 @@ def _select_surface(model_id: str, base_url: str, api_key: str, config_key: str)if model_id in _IMAGE_API_MODELS:return "images"- # Unknown id: keep today's behaviour, but say so once if the dedicated API- # could serve it better.- if model_id not in _HINTED_MODELS:- _HINTED_MODELS.add(model_id)- if model_id in _fetch_image_api_catalog(base_url, api_key):- logger.info(- "model '%s' is available on the OpenRouter Image API, which supports "- "exact aspect ratios, resolution/quality/background/seed and up to 16 "- "reference images. Staying on chat-completions; set "- "image_gen.%s.surface: images (or OPENROUTER_IMAGE_API_SURFACE=images) "- "to use it.",- model_id, config_key,- )+ # Unknown id: the live catalog decides. Most of the endpoint's image+ # models exist only on the dedicated API, so a positive probe must route+ # there — staying on chat would 404/400 a model the live picker offered.+ if model_id in _fetch_image_api_catalog(base_url, api_key):+ return "images"return "chat"diff --git a/tests/plugins/image_gen/test_openrouter_compat_provider.py b/tests/plugins/image_gen/test_openrouter_compat_provider.pyindex 0349b2629a8..b3647376b9e 100644--- a/tests/plugins/image_gen/test_openrouter_compat_provider.py+++ b/tests/plugins/image_gen/test_openrouter_compat_provider.py@@ -202,6 +202,55 @@ class TestLiveCatalog:provider.list_models()assert mock_get.call_count == 1+ def test_picker_merges_image_api_and_chat_catalogs(self):+ """OpenRouter picker = union of /images/models and image-output+ /models entries, deduped, defaults first."""+ from plugins.image_gen.openrouter import _build_providers++ orp = {p.name: p for p in _build_providers()}["openrouter"]++ def fake_get(url, **kw):+ resp = MagicMock()+ resp.raise_for_status = MagicMock()+ if url.endswith("/images/models"):+ resp.json.return_value = {"data": [+ {"id": "bytedance-seed/seedream-4.5", "name": "Seedream 4.5",+ "architecture": {"input_modalities": ["text", "image"],+ "output_modalities": ["image"]}},+ {"id": "openai/gpt-5.4-image-2", "name": "GPT-5.4 Image 2",+ "architecture": {"input_modalities": ["text", "image"],+ "output_modalities": ["image"]}},+ ]}+ else:+ resp.json.return_value = {"data": [+ {"id": "openai/gpt-5.4-image-2",+ "architecture": {"output_modalities": ["image"],+ "input_modalities": ["text", "image"]}},+ {"id": "google/gemini-3-pro-image",+ "architecture": {"output_modalities": ["image"],+ "input_modalities": ["text", "image"]}},+ ]}+ return resp++ with patch(_RUNTIME, return_value=_runtime_ok()), patch("requests.get", side_effect=fake_get):+ ids = [m["id"] for m in orp.list_models()]+ assert ids[0] == "openai/gpt-5.4-image-2" # default first+ assert "bytedance-seed/seedream-4.5" in ids # Image-API-only model present+ assert "google/gemini-3-pro-image" in ids # chat-catalog model present+ assert len(ids) == len(set(ids)) # deduped++ def test_nous_portal_picker_excludes_image_api_catalog(self):+ """Nous Portal has no /images route; its picker must not offer+ Image-API-only models it cannot serve."""+ from plugins.image_gen.openrouter import _build_providers++ nous = {p.name: p for p in _build_providers()}["nous"]+ with patch(_RUNTIME, side_effect=RuntimeError("no creds")):+ ids = [m["id"] for m in nous.list_models()]+ from plugins.image_gen.openrouter import DEFAULT_MODEL, _FALLBACK_MODEL++ assert ids == [DEFAULT_MODEL, _FALLBACK_MODEL]+# ---------------------------------------------------------------------------# Helpers@@ -412,7 +461,6 @@ class TestImageApiSurface:import plugins.image_gen.openrouter as modmod._CATALOG_CACHE.clear()- mod._HINTED_MODELS.clear()monkeypatch.setattr(mod, "_load_image_gen_config", lambda: {})for knob in ("QUALITY", "BACKGROUND", "RESOLUTION", "SEED", "N","ASPECT_RATIO", "TIMEOUT", "SURFACE"):@@ -420,7 +468,6 @@ class TestImageApiSurface:monkeypatch.delenv("OPENROUTER_IMAGE_MODEL", raising=False)yieldmod._CATALOG_CACHE.clear()- mod._HINTED_MODELS.clear()# -- routing ---------------------------------------------------------@@ -450,21 +497,39 @@ class TestImageApiSurface:assert _select_surface(DEFAULT_MODEL, "https://x/api/v1", "k", "openrouter") == "chat"assert _select_surface(_FALLBACK_MODEL, "https://x/api/v1", "k", "openrouter") == "chat"- def test_unknown_catalog_model_is_hinted_once_but_not_rerouted(self):+ def test_unknown_catalog_model_routes_to_image_api(self):+ """An id past the curated snapshot but in the live catalog is served+ by the dedicated API — a model picked from the live picker must not+ fall onto chat-completions and 404."""+ import plugins.image_gen.openrouter as orpfrom plugins.image_gen.openrouter import _select_surface+ orp._CATALOG_CACHE.clear()catalog = MagicMock()catalog.raise_for_status = MagicMock()catalog.json.return_value = {"data": [{"id": "brandnew/model-9"}]}with patch("requests.get", return_value=catalog) as mock_get:- assert _select_surface("brandnew/model-9", "https://x/api/v1", "k", "openrouter") == "chat"- assert _select_surface("brandnew/model-9", "https://x/api/v1", "k", "openrouter") == "chat"- # Hinted once, and the probe never repeats for the same id.+ assert _select_surface("brandnew/model-9", "https://x/api/v1", "k", "openrouter") == "images"+ assert _select_surface("brandnew/model-9", "https://x/api/v1", "k", "openrouter") == "images"+ # Catalog probe is cached — one fetch serves repeat calls.assert mock_get.call_count == 1+ def test_unknown_model_not_in_catalog_stays_on_chat(self):+ import plugins.image_gen.openrouter as orp+ from plugins.image_gen.openrouter import _select_surface++ orp._CATALOG_CACHE.clear()+ catalog = MagicMock()+ catalog.raise_for_status = MagicMock()+ catalog.json.return_value = {"data": [{"id": "something/else"}]}+ with patch("requests.get", return_value=catalog):+ assert _select_surface("not-served/model", "https://x/api/v1", "k", "openrouter") == "chat"+def test_failed_probe_costs_nothing(self):+ import plugins.image_gen.openrouter as orpfrom plugins.image_gen.openrouter import _select_surface+ orp._CATALOG_CACHE.clear()with patch("requests.get", side_effect=OSError("network down")):assert _select_surface("unknown/model", "https://x/api/v1", "k", "openrouter") == "chat"diff --git a/website/docs/user-guide/features/image-generation.md b/website/docs/user-guide/features/image-generation.mdindex ff2f5e4c969..51528d81c61 100644--- a/website/docs/user-guide/features/image-generation.md+++ b/website/docs/user-guide/features/image-generation.md@@ -71,6 +71,33 @@ image_gen:to the global tool-worker limit, so image providers receive bounded parallelrequests without allowing an image batch to bypass the agent's concurrency cap.+### OpenRouter: the full Image API catalog++With `image_gen.provider: openrouter`, the model picker lists OpenRouter's+entire live image catalog — the dedicated+[Image API](https://openrouter.ai/docs/guides/overview/multimodal/image-generation)+models (Seedream, FLUX.2, Recraft, Qwen Image, MAI, Krea, Riverflow, Grok+Imagine, and more — 40+ ids) merged with the chat-completions image models.+The catalog is fetched live from `GET /images/models` and `GET /models`, so+new models appear in the picker as soon as OpenRouter serves them; no Hermes+update needed. Generation routes each model to the surface that serves it+(dedicated `POST /images/generations` vs chat-completions) automatically.+Nous Portal proxies the chat-completions protocol only, so its picker offers+the chat-served models.++Optional per-request knobs for Image API models go under the scoped config+section (or `OPENROUTER_IMAGE_API_*` env vars):++```yaml+image_gen:+ provider: openrouter+ model: bytedance-seed/seedream-4.5+ openrouter:+ resolution: 2K # model-dependent: 1K / 2K / 4K+ quality: high # gpt-image models+ output_format: png+```+### GPT-Image QualityThe `fal-ai/gpt-image-1.5` and `fal-ai/gpt-image-2` request quality is pinned to `medium` (~$0.034–$0.06/image at 1024×1024). We don't expose the `low` / `high` tiers as a user-facing option so that Nous Portal billing stays predictable across all users — the cost spread between tiers is 3–22×. If you want a cheaper option, pick Klein 9B or Z-Image Turbo; if you want higher quality, use Nano Banana Pro or Recraft V4 Pro.@@ -120,6 +147,7 @@ Two inputs drive the edit:| **xAI** (Grok Imagine) | ✓ | 1 | `/v1/images/edits` (`grok-imagine-image-quality`) || **Krea** (`Krea 2`) | ✓ | up to 10 | reference-guided generation (`image_style_references`) || **OpenAI (Codex auth)** | ✓ | up to 16 | Codex Responses `image_generation` tool with `input_image` content parts |+| **OpenRouter** (Image API models) | ✓ | up to 14–16 (per model) | `input_references` on `POST /images/generations`; chat-served models use `image_url` content parts (up to 3) |FAL models with an editing endpoint: `flux-2/klein/9b`, `flux-2-pro`,`nano-banana-pro`, `gpt-image-1.5`, `gpt-image-2`, `ideogram/v3`, and