[wip] OpenRouter: Add model providers endpoint

This commit is contained in:
Cohee 2025-02-02 23:30:44 +02:00
parent 71e1fc91f1
commit bfd57b66ef

View File

@ -4,6 +4,31 @@ import { jsonParser } from '../express-common.js';
export const router = express.Router();
const API_OPENROUTER = 'https://openrouter.ai/api/v1';
router.post('/models/providers', jsonParser, async (req, res) => {
try {
const { model } = req.body;
const response = await fetch(`${API_OPENROUTER}/models/${model}/endpoints`, {
method: 'GET',
headers: {
'Accept': 'application/json',
},
});
if (!response.ok) {
return res.json([]);
}
const data = await response.json();
const endpoints = data?.data?.endpoints || [];
const providerNames = endpoints.map(e => e.provider_name);
return res.json(providerNames);
} catch (error) {
console.error(error);
return res.sendStatus(500);
}
});
router.post('/models/multimodal', jsonParser, async (_req, res) => {
try {
// The endpoint is available without authentication