From 372e76f1a4f94475e0a8c9d41d789f9b5d78e302 Mon Sep 17 00:00:00 2001 From: michaelschal <35957947-michaelschal@users.noreply.replit.com> Date: Wed, 1 Oct 2025 16:27:41 +0000 Subject: [PATCH] Dynamically load AI models from OpenRouter API for content generation Implement a new API endpoint `/api/openrouter/models` to fetch AI model data from OpenRouter and dynamically populate the model selection in the settings page. Replit-Commit-Author: Agent Replit-Commit-Session-Id: ae4037a0-2a6f-4530-9bac-79b543286bda Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/397bca8c-984f-43ff-841a-10897aeb8140/ae4037a0-2a6f-4530-9bac-79b543286bda/HPCBgsr --- client/src/pages/settings.tsx | 15 +++++++++------ server/routes.ts | 21 +++++++++++++++++++++ 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/client/src/pages/settings.tsx b/client/src/pages/settings.tsx index e50c98a..dc72205 100644 --- a/client/src/pages/settings.tsx +++ b/client/src/pages/settings.tsx @@ -33,6 +33,10 @@ export default function Settings() { queryKey: ['/api/openrouter/config'], }); + const { data: openrouterModels } = useQuery({ + queryKey: ['/api/openrouter/models'], + }); + useEffect(() => { if (cloudinaryConfig) { setCloudName((cloudinaryConfig as any).cloudName || ""); @@ -200,12 +204,11 @@ export default function Settings() { - Claude 3.5 Sonnet - Claude 3 Opus - GPT-4o - GPT-4 Turbo - Gemini 1.5 Pro - Llama 3.1 70B + {openrouterModels?.data?.map((model: any) => ( + + {model.name} + + ))}

diff --git a/server/routes.ts b/server/routes.ts index bc69862..9fdf8ab 100644 --- a/server/routes.ts +++ b/server/routes.ts @@ -283,6 +283,27 @@ export async function registerRoutes(app: Express): Promise { } }); + // OpenRouter models list + app.get("/api/openrouter/models", async (req, res) => { + try { + const response = await fetch("https://openrouter.ai/api/v1/models", { + headers: { + "Content-Type": "application/json", + } + }); + + if (!response.ok) { + throw new Error(`OpenRouter API error: ${response.status}`); + } + + const data = await response.json(); + res.json(data); + } catch (error) { + console.error("Error fetching OpenRouter models:", error); + res.status(500).json({ error: "Failed to fetch OpenRouter models" }); + } + }); + // OpenRouter configuration app.get("/api/openrouter/config", async (req, res) => { try {