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
This commit is contained in:
michaelschal committed 2025-10-01 16:27:41 +00:00
1 parent 68ed90b0c9
commit 372e76f1a4
2 files changed
+30 -6

No files matched your search

+21
View File
@@ -283,6 +283,27 @@ export async function registerRoutes(app: Express): Promise<Server> {
}
});
// 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 {