Spaces:
Running
Running
File size: 1,774 Bytes
dce7eca | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | const https = require('https');
const keys = [
'sk-EXpDPvj0PnYh2l5cof3JDGctgYUrWHVN1DjvDxDHi9e7Vq7Z',
'sk-KSUPdEt40yyHwWkymuCA9w5gefrfgJPha5gH23l5Mjdsn6Hq',
'sk-xwPk8wHR3hZR9Ya11LnXci0A70N2QxIwVv9gO43VZ5H3QCrN'
];
function checkBalance(key) {
return new Promise((resolve) => {
console.log(`\nChecking Key: ${key.substring(0, 10)}...`);
const options = {
hostname: 'api.stability.ai',
path: '/v1/user/balance',
method: 'GET',
headers: {
Authorization: `Bearer ${key}`
}
};
const req = https.request(options, (res) => {
let data = '';
res.on('data', (chunk) => data += chunk);
res.on('end', () => {
if (res.statusCode === 200) {
const json = JSON.parse(data);
console.log(`✅ Status: OK`);
console.log(`💰 Credits: ${json.credits}`);
} else {
console.log(`❌ Status: ${res.statusCode}`);
console.log(`📝 Response: ${data}`);
if (res.statusCode === 402) {
console.log('⚠️ Result: Out of credits (402 Payment Required)');
} else if (res.statusCode === 401) {
console.log('⚠️ Result: Invalid API Key (401 Unauthorized)');
}
}
resolve();
});
});
req.on('error', (e) => {
console.error(`❌ Request Error: ${e.message}`);
resolve();
});
req.end();
});
}
async function run() {
for (const key of keys) {
await checkBalance(key);
}
}
run();
|