Skip to content

Instantly share code, notes, and snippets.

@tluyben
Last active March 25, 2025 08:57
Show Gist options
  • Save tluyben/f4ec5dd81da840da3b6b0a4829cb3da1 to your computer and use it in GitHub Desktop.
Save tluyben/f4ec5dd81da840da3b6b0a4829cb3da1 to your computer and use it in GitHub Desktop.
get openrouter models
const modelsData = Array.from(document.querySelectorAll('table.table-fixed tbody tr')).map(row => {
const modelLinkElement = row.querySelector('a.block.text-slate-11.underline');
const modelName = modelLinkElement ? modelLinkElement.textContent.trim() : '';
const modelHref = modelLinkElement ? modelLinkElement.getAttribute('href') : '';
const modelCode = row.querySelector('code.text-xs') ? row.querySelector('code.text-xs').textContent.trim() : '';
// Get price cells
const priceTds = row.querySelectorAll('td.text-center');
// Process prices: extract numeric value, convert to number * 100
const prices = Array.from(priceTds).map(td => {
const priceText = td.textContent.trim();
// If the price is "$0", convert to 0
if (priceText === "$0") return 0;
// If price is "--" or something non-numeric, keep that value
if (priceText === "--" || !/\d/.test(priceText)) return priceText;
// Extract numeric part and remove $ symbol
const numericPart = priceText.replace(/[^\d.]/g, '');
// If it's a valid number, convert to number and multiply by 100
return numericPart ? parseFloat(numericPart) * 100 : priceText;
});
return {
name: modelName,
href: modelHref,
code: modelCode,
prices: prices
};
});
console.log(modelsData);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment