Skip to content

Instantly share code, notes, and snippets.

@ulidtko
Created October 9, 2026 16:26
Show Gist options
  • Select an option

  • Save ulidtko/021952c98afcf059ade26b4390439a95 to your computer and use it in GitHub Desktop.

Select an option

Save ulidtko/021952c98afcf059ade26b4390439a95 to your computer and use it in GitHub Desktop.
/* Scan OpenAI-compatible API for models that converse */
const TOKEN = process.env.TOKEN || (() => { console.error("Provide $TOKEN"); process.exit(1); })()
const APIBASE = process.env.API || 'https://api.openai.com/v1';
const AUTH_HEADERS = {
'Authorization': `Bearer ${TOKEN}`,
'Content-Type': 'application/json'
};
async function runScan() {
let activeModels = [];
try {
console.log("Fetching models...");
const modelsRes = await fetch(`${APIBASE}/models`, { headers: AUTH_HEADERS });
if (!modelsRes.ok) throw new Error(`Failed to get models: ${modelsRes.status}`);
const data = await modelsRes.json();
activeModels = data.data
.filter(m => m.shutdown_date === null)
.map(m => m.id);
} catch (e) {
return { error: e.message };
}
console.log(`Starting scan of ${activeModels.length} models...`);
const successfulModels = [];
let rateLimitsHit = 0;
let totalFailures = 0;
for (let i = 0; i < activeModels.length; i++) {
const id = activeModels[i];
// small delay to not hit rate limits
await new Promise(r => setTimeout(r, Math.floor(Math.random() * 3000) + 100));
try {
process.stdout.write(`Checking ${id}... `);
const response = await fetch(`${APIBASE}/chat/completions`, {
method: 'POST',
headers: AUTH_HEADERS,
body: JSON.stringify({
model: id,
messages: [{ role: 'user', content: 'Hi, say "2+2" and nothing else' }]
})
});
if (response.ok) {
successfulModels.push(id);
console.log("✅ OK");
} else if (response.status === 429) {
rateLimitsHit++;
console.log("❌ RATE LIMITED");
} else {
totalFailures++;
console.log(`❌ FAILED (${response.status})`);
}
} catch (err) {
totalFailures++;
console.log(`❌ ERROR (${err.message})`);
}
}
return {
scannedCount: activeModels.length,
successes: successfulModels.sort(),
failuresTotal: totalFailures,
rateLimitHits: rateLimitsHit
};
}
runScan().then(res => console.log("\nFINAL REPORT:", JSON.stringify(res, null, 2))).catch(e => console.error(e));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment