[wip] OpenRouter: Add model providers endpoint

bfd57b66efde8d8528a5bd519788a110a52528ac

Cohee <18619528+Cohee1207@users.noreply.github.com>

1 files changed, +25 -0Showing whitespace changes
src/endpoints/openrouter.js+25 -0
@@ -4,6 +4,31 @@ import { jsonParser } from '../express-common.js';
44export const router = express.Router();
55const API_OPENROUTER = 'https://openrouter.ai/api/v1';
66
7+router.post('/models/providers', jsonParser, async (req, res) => {
8+ try {
9+ const { model } = req.body;
10+ const response = await fetch(`${API_OPENROUTER}/models/${model}/endpoints`, {
11+ method: 'GET',
12+ headers: {
13+ 'Accept': 'application/json',
14+ },
15+ });
16+
17+ if (!response.ok) {
18+ return res.json([]);
19+ }
20+
21+ const data = await response.json();
22+ const endpoints = data?.data?.endpoints || [];
23+ const providerNames = endpoints.map(e => e.provider_name);
24+
25+ return res.json(providerNames);
26+ } catch (error) {
27+ console.error(error);
28+ return res.sendStatus(500);
29+ }
30+});
31+
732router.post('/models/multimodal', jsonParser, async (_req, res) => {
833 try {
934 // The endpoint is available without authentication