mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-19 21:52:21 +03:00
* feat(providers): optional AI Horde API key and live image catalog Allow a registered Horde key on the no-auth connection and send it for chat and image jobs. List only image models that currently have workers, and generate through Horde's native async API. # Conflicts: # open-sse/config/imageRegistry.ts # src/app/(dashboard)/dashboard/providers/[id]/ProviderDetailPageClient.tsx # src/shared/constants/providers.ts # src/sse/services/auth.ts * fix(providers): validate AI Horde keys against find_user The OpenAI-compatible /v1/models probe returns 200 for any Bearer token on oai.aihorde.net, so Check always succeeded. Use Horde's /v2/find_user lookup instead; an empty key still counts as the optional anonymous path. * chore(changelog): name the AI Horde fragment for #10542 * fix(images): harden AI Horde optional-key selection and outbound fetches - Optional-key selection now honors connection health (rate-limit cooldown and terminal/unavailable test status) before handing a stored key back, rotating to the next healthy key or falling back to the anonymous no-auth path instead of using an unhealthy stored key. - Route the Horde submit/check/status/cancel and catalog calls through the repository's bounded outbound-fetch helper (timeout, no more bare fetch()) and route R2 image downloads through the established bounded remote-image fetch (SSRF host guard, DNS-rebinding pin, streaming byte cap, redirect limit) instead of an unbounded fetch(). - Extend the generation deadline to cover the full request lifecycle (catalog freshness check, submit, polling, and image download), and add a regression test proving that exceeding the deadline issues a DELETE cancel to Horde's API rather than only timing out locally. Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com> --------- Co-authored-by: pqr <pqr@soraka.ititti.es> Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>
999 lines
34 KiB
TypeScript
999 lines
34 KiB
TypeScript
/**
|
|
* Image Generation Provider Registry
|
|
*
|
|
* Defines providers that support the /v1/images/generations endpoint.
|
|
* Each provider has its own request format and endpoint.
|
|
*/
|
|
|
|
import { LMARENA_DIRECT_IMAGE_MODELS } from "./providers/registry/lmarena/directModels.ts";
|
|
import { SEGMIND_IMAGE_PROVIDER } from "./providers/registry/segmind/imageModels.ts";
|
|
import { KIE_IMAGE_MODELS } from "./providers/registry/kie/imageModels.ts";
|
|
import { FREEPIK_IMAGE_PROVIDER } from "./providers/registry/freepik/index.ts";
|
|
import { STABILITY_AI_IMAGE_MODELS } from "./providers/registry/stability-ai/imageModels.ts";
|
|
import { GEMINI_IMAGEN_PROVIDER } from "./providers/registry/gemini/imageModels.ts";
|
|
import { CHEAPERINFERENCE_IMAGE_PROVIDER } from "./providers/registry/cheaperinference/imageModels.ts";
|
|
import {
|
|
ADOBE_FIREFLY_IMAGE_ROUTING_ALIASES,
|
|
toRegistryImageModels,
|
|
} from "../services/adobeFireflyModels.ts";
|
|
import { AI_HORDE_IMAGE_PROVIDER } from "./providers/registry/aihorde/imageModels.ts";
|
|
|
|
interface ImageModelEntry {
|
|
id: string;
|
|
name: string;
|
|
inputModalities?: string[];
|
|
// See STABILITY_AI_IMAGE_MODELS for why this exists: some models accept "text"
|
|
// but mechanically require an image regardless.
|
|
imageRequired?: boolean;
|
|
description?: string;
|
|
isMarket?: boolean;
|
|
supportedSizes?: string[];
|
|
mediaCapabilities?: Record<string, unknown>;
|
|
}
|
|
|
|
interface ImageProviderConfig {
|
|
id: string;
|
|
baseUrl: string;
|
|
fallbackUrl?: string;
|
|
proUrl?: string;
|
|
statusUrl?: string;
|
|
alias?: string;
|
|
authType: string;
|
|
authHeader: string;
|
|
format: string;
|
|
models: ImageModelEntry[];
|
|
routingAliases?: readonly string[];
|
|
supportedSizes: string[];
|
|
}
|
|
|
|
interface ImageModelAliasEntry {
|
|
provider: string;
|
|
model: string;
|
|
name: string;
|
|
listInCatalog: boolean;
|
|
inputModalities?: string[];
|
|
imageRequired?: boolean;
|
|
description?: string;
|
|
mediaCapabilities?: Record<string, unknown>;
|
|
}
|
|
|
|
interface ImageCatalogModelEntry {
|
|
id: string;
|
|
name: string;
|
|
provider: string;
|
|
supportedSizes: string[];
|
|
inputModalities: string[];
|
|
description?: string;
|
|
mediaCapabilities?: Record<string, unknown>;
|
|
}
|
|
|
|
const IMAGE_MODEL_ALIASES: Record<string, ImageModelAliasEntry> = {
|
|
"gemini-3.1-flash-image-preview": {
|
|
provider: "antigravity",
|
|
model: "gemini-3.1-flash-image",
|
|
name: "Gemini 3.1 Flash Image",
|
|
listInCatalog: false,
|
|
},
|
|
"flux-kontext": {
|
|
provider: "black-forest-labs",
|
|
model: "flux-kontext-pro",
|
|
name: "FLUX Kontext Pro",
|
|
listInCatalog: true,
|
|
inputModalities: ["text", "image"],
|
|
},
|
|
"flux-kontext-max": {
|
|
provider: "black-forest-labs",
|
|
model: "flux-kontext-max",
|
|
name: "FLUX Kontext Max",
|
|
listInCatalog: true,
|
|
inputModalities: ["text", "image"],
|
|
},
|
|
"flux-2-max": {
|
|
provider: "black-forest-labs",
|
|
model: "flux-2-max",
|
|
name: "FLUX.2 Max",
|
|
listInCatalog: true,
|
|
inputModalities: ["text", "image"],
|
|
},
|
|
"flux-2-pro": {
|
|
provider: "black-forest-labs",
|
|
model: "flux-2-pro",
|
|
name: "FLUX.2 Pro",
|
|
listInCatalog: true,
|
|
inputModalities: ["text", "image"],
|
|
},
|
|
"flux-2-flex": {
|
|
provider: "black-forest-labs",
|
|
model: "flux-2-flex",
|
|
name: "FLUX.2 Flex",
|
|
listInCatalog: true,
|
|
inputModalities: ["text", "image"],
|
|
},
|
|
"flux-2-dev": {
|
|
provider: "together",
|
|
model: "black-forest-labs/FLUX.2-dev",
|
|
name: "FLUX.2 Dev",
|
|
listInCatalog: true,
|
|
inputModalities: ["text", "image"],
|
|
},
|
|
kontext: {
|
|
provider: "black-forest-labs",
|
|
model: "flux-kontext-pro",
|
|
name: "FLUX Kontext Pro",
|
|
listInCatalog: false,
|
|
inputModalities: ["text", "image"],
|
|
},
|
|
"pollinations/kontext": {
|
|
provider: "black-forest-labs",
|
|
model: "flux-kontext-pro",
|
|
name: "FLUX Kontext Pro",
|
|
listInCatalog: false,
|
|
inputModalities: ["text", "image"],
|
|
},
|
|
};
|
|
|
|
function resolveImageModelAlias(modelStr) {
|
|
const alias = IMAGE_MODEL_ALIASES[modelStr];
|
|
return alias ? { provider: alias.provider, model: alias.model } : null;
|
|
}
|
|
|
|
// A bare alias may only rewrite a provider-prefixed model when it stays on the
|
|
// SAME provider (e.g. `antigravity/gemini-3.1-flash-image-preview` →
|
|
// antigravity's callable `gemini-3.1-flash-image`). A cross-provider bare alias
|
|
// must NOT override an explicit prefix — #9982 removed the unconditional bare
|
|
// fallback because `fal-ai/flux-2-max` was being hijacked to black-forest-labs
|
|
// by the bare `flux-2-max` alias.
|
|
function resolveSameProviderBareAlias(providerId, model) {
|
|
const aliased = resolveImageModelAlias(model);
|
|
return aliased && aliased.provider === providerId ? aliased : null;
|
|
}
|
|
|
|
function findImageModelConfig(providerId, modelId) {
|
|
const provider = IMAGE_PROVIDERS[providerId];
|
|
if (!provider) return null;
|
|
return provider.models.find((model) => model.id === modelId) || null;
|
|
}
|
|
|
|
// Kept out of getImageModelEntry() (which sits at the complexity-ratchet cap) — an
|
|
// alias can override imageRequired directly, else it falls back to its target
|
|
// model's own flag. Consumers coerce the result with Boolean(), so no `?? false`.
|
|
function resolveAliasImageRequired(alias, modelConfig) {
|
|
return alias.imageRequired ?? modelConfig?.imageRequired;
|
|
}
|
|
|
|
export const IMAGE_PROVIDERS: Record<string, ImageProviderConfig> = {
|
|
agnes: {
|
|
id: "agnes",
|
|
baseUrl: "https://apihub.agnes-ai.com/v1/images/generations",
|
|
authType: "apikey",
|
|
authHeader: "bearer",
|
|
format: "agnes-image",
|
|
models: [
|
|
{
|
|
id: "agnes-image-2.1-flash",
|
|
name: "Agnes Image 2.1 Flash",
|
|
inputModalities: ["text", "image"],
|
|
description: "Agnes text-to-image, image-to-image, and multi-image composition model",
|
|
},
|
|
],
|
|
supportedSizes: ["1K", "2K", "3K", "4K"],
|
|
},
|
|
|
|
"qwen-cloud-token-plan": {
|
|
id: "qwen-cloud-token-plan",
|
|
alias: "qct",
|
|
baseUrl:
|
|
"https://token-plan.ap-southeast-1.maas.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation",
|
|
authType: "apikey",
|
|
authHeader: "bearer",
|
|
format: "qwen-token-plan-image",
|
|
models: [
|
|
{
|
|
id: "wan2.7-image",
|
|
name: "Wan 2.7 Image",
|
|
inputModalities: ["text", "image"],
|
|
},
|
|
{
|
|
id: "wan2.7-image-pro",
|
|
name: "Wan 2.7 Image Pro",
|
|
inputModalities: ["text", "image"],
|
|
},
|
|
],
|
|
// Both models share 1K/2K support. The Pro model also accepts explicit 4K
|
|
// dimensions, which callers can still pass through the permissive request schema.
|
|
supportedSizes: ["1024x1024", "2048x2048"],
|
|
},
|
|
|
|
openai: {
|
|
id: "openai",
|
|
baseUrl: "https://api.openai.com/v1/images/generations",
|
|
authType: "apikey",
|
|
authHeader: "bearer",
|
|
format: "openai", // native OpenAI format
|
|
models: [
|
|
{ id: "gpt-image-2", name: "GPT Image 2" },
|
|
{ id: "gpt-image-1.5", name: "GPT Image 1.5" },
|
|
{ id: "gpt-image-1-mini", name: "GPT Image 1 Mini" },
|
|
],
|
|
supportedSizes: ["1024x1024", "1024x1792", "1792x1024"],
|
|
},
|
|
|
|
// Codex exposes image generation only as a Responses-API hosted tool under
|
|
// ChatGPT OAuth. Incoming GPT-Image-style `/v1/images/generations` requests are
|
|
// translated to /responses calls with `tools: [{ type: "image_generation" }]`
|
|
// by handleCodexImageGeneration.
|
|
codex: {
|
|
id: "codex",
|
|
alias: "cx",
|
|
baseUrl: "https://chatgpt.com/backend-api/codex/responses",
|
|
authType: "oauth",
|
|
authHeader: "bearer",
|
|
format: "codex-responses",
|
|
models: [
|
|
{ id: "gpt-5.6-sol", name: "GPT 5.6 Sol (Codex Image)" },
|
|
{ id: "gpt-5.6-terra", name: "GPT 5.6 Terra (Codex Image)" },
|
|
{ id: "gpt-5.6-luna", name: "GPT 5.6 Luna (Codex Image)" },
|
|
],
|
|
supportedSizes: ["1024x1024", "1024x1536", "1536x1024"],
|
|
},
|
|
|
|
"chatgpt-web": {
|
|
id: "chatgpt-web",
|
|
alias: "cgpt-web",
|
|
baseUrl: "https://chatgpt.com/backend-api/f/conversation",
|
|
authType: "apikey",
|
|
authHeader: "cookie",
|
|
format: "chatgpt-web",
|
|
models: [{ id: "gpt-5.5", name: "GPT-5.5 Instant (ChatGPT Web Image)" }],
|
|
supportedSizes: ["1024x1024", "1024x1536", "1536x1024"],
|
|
},
|
|
|
|
"microsoft-designer-web": {
|
|
id: "microsoft-designer-web",
|
|
alias: "msdesigner",
|
|
baseUrl:
|
|
"https://designerapp.officeapps.live.com/designerapp/DallE.ashx?action=GetDallEImagesCogSci",
|
|
authType: "apikey",
|
|
authHeader: "bearer",
|
|
format: "designer-web",
|
|
models: [{ id: "dall-e-3", name: "DALL-E 3 (Microsoft Designer Web)" }],
|
|
supportedSizes: ["1024x1024", "1792x1024", "1024x1792"],
|
|
},
|
|
|
|
xai: {
|
|
id: "xai",
|
|
baseUrl: "https://api.x.ai/v1/images/generations",
|
|
authType: "apikey",
|
|
authHeader: "bearer",
|
|
format: "openai",
|
|
models: [
|
|
{ id: "grok-imagine-image-quality", name: "Grok Imagine Image Quality" },
|
|
{ id: "grok-imagine-image", name: "Grok Imagine Image" },
|
|
],
|
|
supportedSizes: ["1024x1024", "2048x2048"],
|
|
},
|
|
|
|
"vercel-ai-gateway": {
|
|
id: "vercel-ai-gateway",
|
|
alias: "vag",
|
|
baseUrl: "https://ai-gateway.vercel.sh/v1/images/generations",
|
|
authType: "apikey",
|
|
authHeader: "bearer",
|
|
format: "openai",
|
|
models: [
|
|
{ id: "gpt-image-1", name: "GPT Image 1" },
|
|
{ id: "black-forest-labs/flux-1.1-pro", name: "FLUX 1.1 Pro" },
|
|
],
|
|
supportedSizes: ["1024x1024", "1024x1792", "1792x1024"],
|
|
},
|
|
|
|
together: {
|
|
id: "together",
|
|
baseUrl: "https://api.together.xyz/v1/images/generations",
|
|
authType: "apikey",
|
|
authHeader: "bearer",
|
|
format: "openai",
|
|
models: [
|
|
{
|
|
id: "black-forest-labs/FLUX.2-max",
|
|
name: "FLUX.2 Max",
|
|
inputModalities: ["text", "image"],
|
|
},
|
|
{
|
|
id: "black-forest-labs/FLUX.2-pro",
|
|
name: "FLUX.2 Pro",
|
|
inputModalities: ["text", "image"],
|
|
},
|
|
{
|
|
id: "black-forest-labs/FLUX.2-flex",
|
|
name: "FLUX.2 Flex",
|
|
inputModalities: ["text", "image"],
|
|
},
|
|
{
|
|
id: "black-forest-labs/FLUX.2-dev",
|
|
name: "FLUX.2 Dev",
|
|
inputModalities: ["text", "image"],
|
|
},
|
|
{ id: "openai/gpt-image-1.5", name: "GPT Image 1.5", inputModalities: ["text", "image"] },
|
|
{ id: "Wan-AI/Wan2.6-image", name: "Wan 2.6 Image", inputModalities: ["text", "image"] },
|
|
{
|
|
id: "Qwen/Qwen-Image-2.0-Pro",
|
|
name: "Qwen Image 2.0 Pro",
|
|
inputModalities: ["text", "image"],
|
|
},
|
|
{ id: "Qwen/Qwen-Image-2.0", name: "Qwen Image 2.0", inputModalities: ["text", "image"] },
|
|
{ id: "google/flash-image-3.1", name: "NanoBanana 2", inputModalities: ["text", "image"] },
|
|
{
|
|
id: "google/gemini-3-pro-image",
|
|
name: "NanoBanana Pro",
|
|
inputModalities: ["text", "image"],
|
|
},
|
|
],
|
|
supportedSizes: ["1024x1024", "512x512"],
|
|
},
|
|
|
|
fireworks: {
|
|
id: "fireworks",
|
|
baseUrl: "https://api.fireworks.ai/inference/v1/images/generations",
|
|
authType: "apikey",
|
|
authHeader: "bearer",
|
|
format: "openai",
|
|
models: [
|
|
{ id: "accounts/fireworks/flux-kontext-max", name: "FLUX Kontext Max" },
|
|
{ id: "accounts/fireworks/flux-kontext-pro", name: "FLUX Kontext Pro" },
|
|
{ id: "accounts/fireworks/flux-1-schnell-fp8", name: "FLUX.1 schnell" },
|
|
{ id: "accounts/fireworks/models/flux-1-dev-fp8", name: "FLUX 1 Dev FP8" },
|
|
{ id: "accounts/fireworks/models/stable-diffusion-xl-1024-v1-0", name: "SDXL 1024 v1.0" },
|
|
],
|
|
supportedSizes: ["1024x1024", "512x512"],
|
|
},
|
|
|
|
antigravity: {
|
|
id: "antigravity",
|
|
baseUrl: "https://daily-cloudcode-pa.googleapis.com/v1internal:generateContent",
|
|
authType: "oauth",
|
|
authHeader: "bearer",
|
|
format: "gemini-image", // Special format: uses Gemini generateContent API
|
|
models: [{ id: "gemini-3.1-flash-image", name: "Gemini 3.1 Flash Image" }],
|
|
supportedSizes: ["1024x1024"],
|
|
},
|
|
|
|
// Google AI Studio Imagen family — dedicated :predict endpoint, not generateContent.
|
|
// See providers/registry/gemini/imageModels.ts for the full rationale.
|
|
gemini: GEMINI_IMAGEN_PROVIDER,
|
|
|
|
//Curruntly no models serving
|
|
nebius: {
|
|
id: "nebius",
|
|
baseUrl: "https://api.tokenfactory.nebius.com/v1/images/generations",
|
|
fallbackUrl: "https://api.studio.nebius.com/v1/images/generations",
|
|
authType: "apikey",
|
|
authHeader: "bearer",
|
|
format: "openai",
|
|
models: [{ id: "black-forest-labs/flux-schnell", name: "No Model yet" }],
|
|
supportedSizes: ["1024x1024"],
|
|
},
|
|
|
|
hyperbolic: {
|
|
id: "hyperbolic",
|
|
baseUrl: "https://api.hyperbolic.xyz/v1/image/generation",
|
|
authType: "apikey",
|
|
authHeader: "bearer",
|
|
format: "hyperbolic", // custom: uses model_name, returns base64 images
|
|
models: [{ id: "SDXL1.0-base", name: "No Model yet" }],
|
|
supportedSizes: ["1024x1024"],
|
|
},
|
|
//Curruntly no models serving
|
|
|
|
nanobanana: {
|
|
id: "nanobanana",
|
|
baseUrl: "https://api.nanobananaapi.ai/api/v1/nanobanana/generate",
|
|
proUrl: "https://api.nanobananaapi.ai/api/v1/nanobanana/generate-pro",
|
|
statusUrl: "https://api.nanobananaapi.ai/api/v1/nanobanana/record-info",
|
|
authType: "apikey",
|
|
authHeader: "bearer",
|
|
format: "nanobanana", // custom format (async: submit task, then poll)
|
|
models: [
|
|
{ id: "nanobanana-flash", name: "NanoBanana Flash (Gemini 2.5 Flash)" },
|
|
{ id: "nanobanana-pro", name: "NanoBanana Pro (Gemini 3 Pro)" },
|
|
],
|
|
supportedSizes: ["1024x1024", "1024x1280", "1024x1536", "1536x1024", "1280x1024"],
|
|
},
|
|
|
|
kie: {
|
|
id: "kie",
|
|
baseUrl: "https://api.kie.ai",
|
|
statusUrl: "https://api.kie.ai/api/v1/jobs/recordInfo",
|
|
authType: "apikey",
|
|
authHeader: "bearer",
|
|
format: "kie-image",
|
|
models: KIE_IMAGE_MODELS,
|
|
supportedSizes: ["1:1", "16:9", "9:16", "4:3", "3:4"],
|
|
},
|
|
|
|
haiper: {
|
|
id: "haiper",
|
|
baseUrl: "https://api.haiper.ai/v1/jobs/gen2/text2image",
|
|
statusUrl: "https://api.haiper.ai/v1/jobs",
|
|
authType: "apikey",
|
|
authHeader: "HAIPER_KEY",
|
|
format: "haiper-image",
|
|
models: [{ id: "gen2", name: "Gen 2 Image" }],
|
|
supportedSizes: ["16:9", "9:16", "1:1", "4:3", "3:4"],
|
|
},
|
|
// #2482: MiniMax already has entries in musicRegistry/audioRegistry/videoRegistry,
|
|
// but was missing an image provider entirely, so MiniMax image-model requests
|
|
// fell through the format dispatch below to a 400/unmatched-format response.
|
|
minimax: {
|
|
id: "minimax",
|
|
baseUrl: "https://api.minimax.io/v1/image_generation",
|
|
authType: "apikey",
|
|
authHeader: "bearer",
|
|
format: "minimax-image",
|
|
models: [
|
|
{ id: "image-01", name: "MiniMax Image-01" },
|
|
{ id: "image-01-live", name: "MiniMax Image-01 Live" },
|
|
],
|
|
supportedSizes: ["1:1", "16:9", "9:16", "4:3", "3:4", "3:2", "2:3", "1024x1024"],
|
|
},
|
|
leonardo: {
|
|
id: "leonardo",
|
|
baseUrl: "https://cloud.leonardo.ai/api/rest/v1/generations",
|
|
authType: "apikey",
|
|
authHeader: "bearer",
|
|
format: "leonardo-image",
|
|
models: [
|
|
{ id: "phoenix", name: "Phoenix" },
|
|
{ id: "sdxl", name: "SDXL" },
|
|
],
|
|
supportedSizes: ["1024x1024", "1024x576", "576x1024"],
|
|
},
|
|
ideogram: {
|
|
id: "ideogram",
|
|
baseUrl: "https://api.ideogram.ai/generate",
|
|
authType: "apikey",
|
|
authHeader: "Api-Key",
|
|
format: "ideogram-image",
|
|
models: [
|
|
{ id: "V_3", name: "Ideogram V3" },
|
|
{ id: "V_2A", name: "Ideogram V2A" },
|
|
],
|
|
supportedSizes: ["1024x1024", "1024x1792", "1792x1024"],
|
|
},
|
|
freepik: FREEPIK_IMAGE_PROVIDER,
|
|
sdwebui: {
|
|
id: "sdwebui",
|
|
baseUrl: "http://localhost:7860/sdapi/v1/txt2img",
|
|
authType: "none",
|
|
authHeader: "none",
|
|
format: "sdwebui",
|
|
models: [
|
|
{ id: "stable-diffusion-v1-5", name: "Stable Diffusion v1.5" },
|
|
{ id: "sdxl-base-1.0", name: "SDXL Base 1.0" },
|
|
],
|
|
supportedSizes: ["512x512", "768x768", "1024x1024"],
|
|
},
|
|
|
|
comfyui: {
|
|
id: "comfyui",
|
|
baseUrl: "http://localhost:8188",
|
|
authType: "none",
|
|
authHeader: "none",
|
|
format: "comfyui",
|
|
models: [
|
|
{ id: "flux-dev", name: "FLUX Dev" },
|
|
{ id: "sdxl", name: "SDXL" },
|
|
],
|
|
supportedSizes: ["512x512", "768x768", "1024x1024"],
|
|
},
|
|
|
|
openrouter: {
|
|
id: "openrouter",
|
|
baseUrl: "https://openrouter.ai/api/v1/images/generations",
|
|
authType: "apikey",
|
|
authHeader: "bearer",
|
|
format: "openai",
|
|
models: [
|
|
{ id: "openai/gpt-5.4-image-2", name: "GPT Image 2 (via OpenRouter)" },
|
|
{ id: "openai/gpt-5-image-mini", name: "GPT Image 1 Mini (via OpenRouter)" },
|
|
{ id: "google/gemini-3.1-flash-image-preview", name: "Nano Banana 2 (via OpenRouter)" },
|
|
{ id: "google/gemini-3-pro-image-preview", name: "Nano Banana Pro (via OpenRouter)" },
|
|
{ id: "black-forest-labs/flux.2-max", name: "FLUX.2 Max (via OpenRouter)" },
|
|
{ id: "black-forest-labs/flux.2-pro", name: "FLUX.2 Pro (via OpenRouter)" },
|
|
{ id: "black-forest-labs/flux.2-flex", name: "FLUX.2 Flex (via OpenRouter)" },
|
|
],
|
|
supportedSizes: ["1024x1024", "1024x1792", "1792x1024"],
|
|
},
|
|
|
|
pollinations: {
|
|
id: "pollinations",
|
|
alias: "pol",
|
|
baseUrl: "https://gen.pollinations.ai/v1/images/generations",
|
|
authType: "apikey",
|
|
authHeader: "bearer",
|
|
format: "openai",
|
|
models: [
|
|
{ id: "klein", name: "FLUX.2 Klein 4B" },
|
|
{ id: "flux", name: "Flux Schnell" },
|
|
{ id: "zimage", name: "Z-Image Turbo" },
|
|
{ id: "qwen-image", name: "Qwen Image Plus" },
|
|
{ id: "wan-image", name: "Wan 2.7 Image" },
|
|
{ id: "gpt-image-2", name: "GPT Image 2" },
|
|
{ id: "gptimage-large", name: "GPT Image 1.5" },
|
|
{ id: "gptimage", name: "GPT Image 1 Mini" },
|
|
],
|
|
supportedSizes: ["1024x1024", "512x512"],
|
|
},
|
|
|
|
"fal-ai": {
|
|
id: "fal-ai",
|
|
baseUrl: "https://fal.run",
|
|
authType: "apikey",
|
|
authHeader: "key",
|
|
format: "fal-ai",
|
|
models: [
|
|
{ id: "flux-2-max", name: "FLUX.2 Max" },
|
|
{ id: "flux-2-pro", name: "FLUX.2 Pro" },
|
|
{ id: "flux-2-flex", name: "FLUX.2 Flex" },
|
|
{ id: "bria/text-to-image/3.2", name: "Bria 3.2" },
|
|
{ id: "bytedance/seedream/v4.5/text-to-image", name: "SeeDream V4.5" },
|
|
{ id: "bytedance/dreamina/v3.1/text-to-image", name: "Dreamina V3.1" },
|
|
{ id: "ideogram/v3", name: "Ideogram V3" },
|
|
// Prefix-only on purpose: adobe-firefly owns the bare nano-banana ids
|
|
// (operator decision 2026-07-31, pinned by cheaperinference-image-models
|
|
// guard). The dispatch path tolerates the fal-ai/ prefix (fal.ts).
|
|
{ id: "fal-ai/nano-banana-pro", name: "Nano Banana Pro" },
|
|
{ id: "fal-ai/nano-banana-2", name: "Nano Banana 2" },
|
|
{ id: "recraft/v4/pro/text-to-image", name: "Recraft V4 Pro via Fal" },
|
|
{ id: "recraft/v4/text-to-image", name: "Recraft V4 via Fal" },
|
|
{ id: "stable-diffusion-v35-medium", name: "Stable Diffusion v3.5 Medium" },
|
|
],
|
|
supportedSizes: ["1024x1024", "1024x1280", "1280x1024"],
|
|
},
|
|
|
|
"stability-ai": {
|
|
id: "stability-ai",
|
|
baseUrl: "https://api.stability.ai",
|
|
authType: "apikey",
|
|
authHeader: "bearer",
|
|
format: "stability-ai",
|
|
models: STABILITY_AI_IMAGE_MODELS,
|
|
supportedSizes: ["1024x1024", "1024x1280", "1280x1024"],
|
|
},
|
|
|
|
"black-forest-labs": {
|
|
id: "black-forest-labs",
|
|
baseUrl: "https://api.bfl.ai",
|
|
authType: "apikey",
|
|
authHeader: "x-key",
|
|
format: "black-forest-labs",
|
|
models: [
|
|
{ id: "flux-2-max", name: "FLUX.2 Max" },
|
|
{ id: "flux-2-pro", name: "FLUX.2 Pro" },
|
|
{ id: "flux-2-flex", name: "FLUX.2 Flex" },
|
|
{ id: "flux-pro-1.1-ultra", name: "flux-pro-1.1-ultra" },
|
|
{ id: "flux-pro-1.1", name: "flux-pro-1.1" },
|
|
{ id: "flux-2-klein-9b", name: "flux 2 Klein 9B" },
|
|
{ id: "flux-2-klein-4b", name: "flux 2 Klein 4B" },
|
|
{ id: "flux-kontext-max", name: "flux-kontext-max", inputModalities: ["text", "image"] },
|
|
{ id: "flux-kontext-pro", name: "flux-kontext-pro", inputModalities: ["text", "image"] },
|
|
{ id: "flux-dev", name: "flux-dev" },
|
|
{ id: "flux-pro", name: "flux-pro" },
|
|
],
|
|
supportedSizes: ["1024x1024", "1024x1280", "1280x1024"],
|
|
},
|
|
|
|
recraft: {
|
|
id: "recraft",
|
|
baseUrl: "https://external.api.recraft.ai",
|
|
authType: "apikey",
|
|
authHeader: "bearer",
|
|
format: "recraft",
|
|
models: [
|
|
{ id: "recraftv4_pro", name: "Recraft V4 Pro" },
|
|
{ id: "recraftv4", name: "Recraft V4" },
|
|
{ id: "recraftv3", name: "Recraft V3" },
|
|
{ id: "recraftv2", name: "Recraft V2" },
|
|
],
|
|
supportedSizes: ["1024x1024", "1024x1280", "1280x1024"],
|
|
},
|
|
|
|
topaz: {
|
|
id: "topaz",
|
|
baseUrl: "https://api.topazlabs.com",
|
|
authType: "apikey",
|
|
authHeader: "x-api-key",
|
|
format: "topaz",
|
|
models: [{ id: "topaz-enhance", name: "topaz-enhance", inputModalities: ["image"] }],
|
|
supportedSizes: ["1024x1024"],
|
|
},
|
|
|
|
// Segmind (#6656): 200+ models, `POST /v1/{model}`, x-api-key, raw image bytes.
|
|
segmind: SEGMIND_IMAGE_PROVIDER,
|
|
nanogpt: {
|
|
id: "nanogpt",
|
|
baseUrl: "https://nano-gpt.com/api/v1/images/generations",
|
|
authType: "apikey",
|
|
authHeader: "bearer",
|
|
format: "openai",
|
|
models: [
|
|
{ id: "qwen-image", name: "Qwen Image", inputModalities: ["text", "image"] },
|
|
{ id: "z-image-turbo", name: "Z Image Turbo" },
|
|
{ id: "chroma", name: "Chroma" },
|
|
{ id: "hidream", name: "Hidream I1 Full" },
|
|
],
|
|
supportedSizes: ["1024x1024", "1024x1280", "1280x1024"],
|
|
},
|
|
|
|
// NVIDIA NIM image generation (FLUX models). Distinct from the NVIDIA *chat* entry
|
|
// (open-sse/config/providers/registry/nvidia/index.ts, host integrate.api.nvidia.com,
|
|
// OpenAI-compatible) — image generation lives on ai.api.nvidia.com/v1/genai/<model>
|
|
// with a native NIM body per model, so it gets a dedicated `nvidia-nim` format/handler
|
|
// (handleNvidiaNimImageGeneration) rather than reusing the OpenAI image path.
|
|
// Ported from upstream 9router#1195.
|
|
nvidia: {
|
|
id: "nvidia",
|
|
baseUrl: "https://ai.api.nvidia.com/v1/genai",
|
|
authType: "apikey",
|
|
authHeader: "bearer",
|
|
format: "nvidia-nim",
|
|
models: [
|
|
{
|
|
id: "black-forest-labs/flux.1-dev",
|
|
name: "FLUX.1 Dev",
|
|
inputModalities: ["text", "image"],
|
|
},
|
|
{ id: "black-forest-labs/flux.1-schnell", name: "FLUX.1 Schnell" },
|
|
{
|
|
id: "black-forest-labs/flux.1-kontext-dev",
|
|
name: "FLUX.1 Kontext Dev (Edit)",
|
|
inputModalities: ["text", "image"],
|
|
},
|
|
{
|
|
id: "black-forest-labs/flux.2-klein-4b",
|
|
name: "FLUX.2 Klein 4B",
|
|
inputModalities: ["text", "image"],
|
|
},
|
|
],
|
|
supportedSizes: ["1024x1024", "768x1344", "512x512"],
|
|
},
|
|
|
|
// SenseNova (商汤日日新) Text-to-Image on the free Token Plan. OpenAI-compatible
|
|
// `/v1/images/generations`, so the generic OpenAI image handler routes it — same
|
|
// SenseNova api-key/connection as the chat provider. (9router#2233)
|
|
sensenova: {
|
|
id: "sensenova",
|
|
baseUrl: "https://api.sensenova.cn/v1/images/generations",
|
|
authType: "apikey",
|
|
authHeader: "bearer",
|
|
format: "openai",
|
|
models: [{ id: "sensenova-u1-fast", name: "SenseNova U1 Fast" }],
|
|
supportedSizes: ["1024x1024"],
|
|
},
|
|
|
|
// HuggingFace Hub Inference API text-to-image task. Returns raw image bytes
|
|
// (not JSON), so it uses a dedicated "huggingface-image" format handled by
|
|
// handleHuggingFaceImageGeneration. Same base URL convention as the HF
|
|
// STT/TTS entries in audioRegistry.ts. Model list is deliberately small —
|
|
// the dashboard's "suggested models" chip row (GET
|
|
// /api/v1/providers/suggested-models) surfaces additional HF Hub models
|
|
// beyond this seed list.
|
|
huggingface: {
|
|
id: "huggingface",
|
|
// HF retired api-inference.huggingface.co; text-to-image now routes through
|
|
// router.huggingface.co with the hf-inference provider pinned in the path.
|
|
baseUrl: "https://router.huggingface.co/hf-inference/models",
|
|
authType: "apikey",
|
|
authHeader: "bearer",
|
|
format: "huggingface-image",
|
|
models: [
|
|
{ id: "black-forest-labs/FLUX.1-dev", name: "FLUX.1 Dev (HF)" },
|
|
{ id: "black-forest-labs/FLUX.1-schnell", name: "FLUX.1 Schnell (HF)" },
|
|
{ id: "stabilityai/stable-diffusion-xl-base-1.0", name: "Stable Diffusion XL (HF)" },
|
|
],
|
|
supportedSizes: ["1024x1024"],
|
|
},
|
|
|
|
// Arena (formerly LMArena) Direct-chat Image category (static scrape 2026-07-09).
|
|
// Not listed in the chat registry — image catalog only. Generation path still
|
|
// uses cookie session auth via the lmarena provider connection (stable wire id).
|
|
lmarena: {
|
|
id: "lmarena",
|
|
alias: "lma",
|
|
baseUrl: "https://arena.ai/nextjs-api/stream/create-evaluation",
|
|
authType: "apikey",
|
|
authHeader: "cookie",
|
|
format: "openai",
|
|
models: LMARENA_DIRECT_IMAGE_MODELS,
|
|
supportedSizes: ["1024x1024", "1024x1792", "1792x1024"],
|
|
},
|
|
|
|
// Adobe Firefly (unofficial) — IMS access_token (clio-playground-web) or browser
|
|
// Cookie from firefly.adobe.com. Async 3P image generate + poll.
|
|
// Model list = static fallback from models/discovery capture; live discovery
|
|
// refreshes via resolveAdobeFireflyCatalog when credentials work.
|
|
"adobe-firefly": {
|
|
id: "adobe-firefly",
|
|
alias: "firefly",
|
|
baseUrl: "https://firefly-3p.ff.adobe.io/v2/3p-images/generate-async",
|
|
authType: "apikey",
|
|
authHeader: "bearer",
|
|
format: "adobe-firefly-image",
|
|
models: toRegistryImageModels(),
|
|
routingAliases: ADOBE_FIREFLY_IMAGE_ROUTING_ALIASES,
|
|
supportedSizes: [],
|
|
},
|
|
|
|
// Cheaper Inference (OSS-sponsor gateway). Declared AFTER adobe-firefly on
|
|
// purpose: it shares the nano-banana-pro / nano-banana-2 ids, and parseImageModel
|
|
// resolves a bare id by first-match over this object's iteration order, so
|
|
// Firefly keeps the bare ids and these are prefix-only. See the module for the
|
|
// full collision note.
|
|
cheaperinference: CHEAPERINFERENCE_IMAGE_PROVIDER,
|
|
|
|
// Keep Bailian Coding Plan after existing duplicate model owners so adding
|
|
// explicit `bailian-coding-plan/` and `bcp/` routes does not change
|
|
// historical bare-model routing.
|
|
"bailian-coding-plan": {
|
|
id: "bailian-coding-plan",
|
|
alias: "bcp",
|
|
baseUrl:
|
|
"https://coding-intl.dashscope.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation",
|
|
authType: "apikey",
|
|
authHeader: "bearer",
|
|
format: "bailian-coding-plan-image",
|
|
models: [
|
|
{
|
|
id: "wan2.7-image",
|
|
name: "Wan 2.7 Image",
|
|
inputModalities: ["text", "image"],
|
|
},
|
|
{
|
|
id: "wan2.7-image-pro",
|
|
name: "Wan 2.7 Image Pro",
|
|
inputModalities: ["text", "image"],
|
|
},
|
|
{
|
|
id: "qwen-image-2.0",
|
|
name: "Qwen Image 2.0",
|
|
inputModalities: ["text", "image"],
|
|
},
|
|
{
|
|
id: "qwen-image-2.0-pro",
|
|
name: "Qwen Image 2.0 Pro",
|
|
inputModalities: ["text", "image"],
|
|
},
|
|
],
|
|
supportedSizes: ["1024x1024", "2048x2048"],
|
|
},
|
|
|
|
// Keep Alibaba after existing duplicate model owners so adding explicit
|
|
// `alibaba/` and `ali/` routes does not change historical bare-model routing.
|
|
alibaba: {
|
|
id: "alibaba",
|
|
alias: "ali",
|
|
baseUrl:
|
|
"https://dashscope-intl.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation",
|
|
authType: "apikey",
|
|
authHeader: "bearer",
|
|
format: "alibaba-image",
|
|
models: [
|
|
{
|
|
id: "qwen-image-3.0-pro",
|
|
name: "Qwen Image 3.0 Pro",
|
|
inputModalities: ["text", "image"],
|
|
},
|
|
{
|
|
id: "qwen-image-2.0-pro-2026-06-22",
|
|
name: "Qwen Image 2.0 Pro (2026-06-22)",
|
|
inputModalities: ["text", "image"],
|
|
},
|
|
{
|
|
id: "qwen-image-2.0",
|
|
name: "Qwen Image 2.0",
|
|
inputModalities: ["text", "image"],
|
|
},
|
|
{ id: "z-image-turbo", name: "Z-Image Turbo" },
|
|
{ id: "wan2.6-t2i", name: "Wan 2.6 T2I" },
|
|
],
|
|
supportedSizes: ["1024x1024", "1280x1280", "2048x2048"],
|
|
},
|
|
|
|
// Keep regular Qwen Cloud isolated from Alibaba, Bailian Coding Plan, and
|
|
// Qwen Cloud Token Plan. Explicit `qwen-cloud/` or `qwc/` routes use only
|
|
// the regular Qwen Cloud connection and its regional DashScope endpoint.
|
|
"qwen-cloud": {
|
|
id: "qwen-cloud",
|
|
alias: "qwc",
|
|
baseUrl:
|
|
"https://dashscope-intl.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation",
|
|
authType: "apikey",
|
|
authHeader: "bearer",
|
|
format: "qwen-cloud-image",
|
|
models: [
|
|
{
|
|
id: "wan2.7-image-pro",
|
|
name: "Wan 2.7 Image Pro",
|
|
inputModalities: ["text", "image"],
|
|
},
|
|
{
|
|
id: "wan2.7-image",
|
|
name: "Wan 2.7 Image",
|
|
inputModalities: ["text", "image"],
|
|
},
|
|
{
|
|
id: "qwen-image-3.0-pro",
|
|
name: "Qwen Image 3.0 Pro",
|
|
inputModalities: ["text", "image"],
|
|
},
|
|
{
|
|
id: "qwen-image-2.0-pro-2026-06-22",
|
|
name: "Qwen Image 2.0 Pro (2026-06-22)",
|
|
inputModalities: ["text", "image"],
|
|
},
|
|
{
|
|
id: "qwen-image-2.0-2026-03-03",
|
|
name: "Qwen Image 2.0 (2026-03-03)",
|
|
inputModalities: ["text", "image"],
|
|
},
|
|
{ id: "z-image-turbo", name: "Z-Image Turbo" },
|
|
],
|
|
// 1K/2K are shared by the whole catalog. Wan 2.7 Image Pro callers can
|
|
// still pass supported 4K dimensions through the permissive request schema.
|
|
supportedSizes: ["1024x1024", "2048x2048"],
|
|
},
|
|
aihorde: AI_HORDE_IMAGE_PROVIDER,
|
|
};
|
|
|
|
/**
|
|
* Get image provider config by ID
|
|
*/
|
|
export function getImageProvider(providerId) {
|
|
return IMAGE_PROVIDERS[providerId] || null;
|
|
}
|
|
|
|
/**
|
|
* Parse image model string (format: "provider/model")
|
|
* Returns { provider, model }
|
|
*/
|
|
export function parseImageModel(modelStr) {
|
|
if (!modelStr) return { provider: null, model: null };
|
|
|
|
const directAlias = resolveImageModelAlias(modelStr);
|
|
if (directAlias) {
|
|
return directAlias;
|
|
}
|
|
|
|
// Try each provider prefix
|
|
for (const [providerId, config] of Object.entries(IMAGE_PROVIDERS)) {
|
|
if (modelStr.startsWith(providerId + "/")) {
|
|
const model = modelStr.slice(providerId.length + 1);
|
|
const aliased =
|
|
resolveImageModelAlias(`${providerId}/${model}`) ||
|
|
resolveSameProviderBareAlias(providerId, model);
|
|
return aliased || { provider: providerId, model };
|
|
}
|
|
// Check alias if available
|
|
if (config.alias && modelStr.startsWith(config.alias + "/")) {
|
|
const model = modelStr.slice(config.alias.length + 1);
|
|
const aliased =
|
|
resolveImageModelAlias(`${providerId}/${model}`) ||
|
|
resolveSameProviderBareAlias(providerId, model);
|
|
return aliased || { provider: providerId, model };
|
|
}
|
|
}
|
|
|
|
// No provider prefix — try to find the model in every provider
|
|
for (const [providerId, config] of Object.entries(IMAGE_PROVIDERS)) {
|
|
if (config.routingAliases?.includes(modelStr) || config.models.some((m) => m.id === modelStr)) {
|
|
return { provider: providerId, model: modelStr };
|
|
}
|
|
}
|
|
|
|
return { provider: null, model: modelStr };
|
|
}
|
|
|
|
/**
|
|
* Get all image models as a flat list
|
|
*/
|
|
function imageProviderCatalogEntries(
|
|
providerId: string,
|
|
config: ImageProviderConfig
|
|
): ImageCatalogModelEntry[] {
|
|
return config.models.map((model) => ({
|
|
id: `${providerId}/${model.id}`,
|
|
name: model.name,
|
|
provider: providerId,
|
|
supportedSizes: model.supportedSizes || config.supportedSizes,
|
|
inputModalities: model.inputModalities || ["text"],
|
|
description: model.description || undefined,
|
|
mediaCapabilities: model.mediaCapabilities,
|
|
}));
|
|
}
|
|
|
|
function imageAliasCatalogEntry(
|
|
alias: string,
|
|
target: ImageModelAliasEntry
|
|
): ImageCatalogModelEntry | null {
|
|
if (!target.listInCatalog) return null;
|
|
|
|
const providerConfig = IMAGE_PROVIDERS[target.provider];
|
|
const modelConfig = findImageModelConfig(target.provider, target.model);
|
|
return {
|
|
id: alias,
|
|
name: target.name || modelConfig?.name || alias,
|
|
provider: target.provider,
|
|
supportedSizes: providerConfig?.supportedSizes || [],
|
|
inputModalities: target.inputModalities || modelConfig?.inputModalities || ["text"],
|
|
description: target.description || modelConfig?.description || undefined,
|
|
};
|
|
}
|
|
|
|
export function getAllImageModels(): ImageCatalogModelEntry[] {
|
|
const providerModels = Object.entries(IMAGE_PROVIDERS).flatMap(([providerId, config]) =>
|
|
imageProviderCatalogEntries(providerId, config)
|
|
);
|
|
const aliasModels = Object.entries(IMAGE_MODEL_ALIASES).flatMap(([alias, target]) => {
|
|
const entry = imageAliasCatalogEntry(alias, target);
|
|
return entry ? [entry] : [];
|
|
});
|
|
return [...providerModels, ...aliasModels];
|
|
}
|
|
|
|
export function getImageModelAliases() {
|
|
return IMAGE_MODEL_ALIASES;
|
|
}
|
|
|
|
/**
|
|
* #6457 — precise provider+modelId membership check against the image registry.
|
|
* Unlike getImageModelEntry() (which also resolves bare aliases and unprefixed
|
|
* ids by scanning every provider), this only answers "is `modelId` registered
|
|
* as an image model under this exact `providerId`?" — used by the chat catalog
|
|
* builder to keep upstream-discovered models (e.g. HuggingFace's live
|
|
* `/v1/models`, which returns image/diffusion models with no modality field)
|
|
* out of the chat listing when they are already known image-only models.
|
|
*/
|
|
export function isRegisteredImageModel(providerId, modelId) {
|
|
return Boolean(findImageModelConfig(providerId, modelId));
|
|
}
|
|
export function getImageModelEntry(modelStr) {
|
|
if (!modelStr) return null;
|
|
|
|
const alias = IMAGE_MODEL_ALIASES[modelStr];
|
|
if (alias) {
|
|
const modelConfig = findImageModelConfig(alias.provider, alias.model);
|
|
return {
|
|
provider: alias.provider,
|
|
model: alias.model,
|
|
inputModalities: alias.inputModalities || modelConfig?.inputModalities || ["text"],
|
|
imageRequired: resolveAliasImageRequired(alias, modelConfig),
|
|
description: alias.description || modelConfig?.description || undefined,
|
|
};
|
|
}
|
|
|
|
const { provider, model } = parseImageModel(modelStr);
|
|
if (!provider || !model) return null;
|
|
|
|
const modelConfig = findImageModelConfig(provider, model);
|
|
if (!modelConfig) return null;
|
|
|
|
return {
|
|
provider,
|
|
model,
|
|
inputModalities: modelConfig.inputModalities || ["text"],
|
|
imageRequired: modelConfig.imageRequired,
|
|
description: modelConfig.description || undefined,
|
|
};
|
|
}
|
|
|
|
/**
|
|
* An image input is only MANDATORY for edit-only models — those whose modalities
|
|
* are `["image"]` with no `"text"`. Models listing both `["text", "image"]` accept
|
|
* an image but can also run pure text-to-image, so they must NOT be gated on an
|
|
* image input (that gate previously blocked 41 dual-modality t2i models).
|
|
*/
|
|
export function modalitiesRequireImageInput(inputModalities) {
|
|
const list = Array.isArray(inputModalities) ? inputModalities : ["text"];
|
|
return list.includes("image") && !list.includes("text");
|
|
}
|