| 4 | export const router = express.Router(); | 4 | export const router = express.Router(); |
| 5 | const API_OPENROUTER = 'https://openrouter.ai/api/v1'; | 5 | const API_OPENROUTER = 'https://openrouter.ai/api/v1'; |
| 6 | | 6 | |
| | 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 | |
| 7 | router.post('/models/multimodal', jsonParser, async (_req, res) => { | 32 | router.post('/models/multimodal', jsonParser, async (_req, res) => { |
| 8 | try { | 33 | try { |
| 9 | // The endpoint is available without authentication | 34 | // The endpoint is available without authentication |