Skip to content

Instantly share code, notes, and snippets.

@PawanOsman
Last active December 13, 2023 19:45
Show Gist options
  • Save PawanOsman/25c88e5831680dc34275d8a9a350e1c0 to your computer and use it in GitHub Desktop.
Save PawanOsman/25c88e5831680dc34275d8a9a350e1c0 to your computer and use it in GitHub Desktop.
This Node.js file is designed to revoke multiple OpenAI API keys. It allows users to input a list of API keys and automatically revokes them using OpenAI's API. The file utilizes the Axios library to send HTTP requests to the OpenAI API and parses the response to determine if the revocation was successful.

OpenAI Key Revoker

This Node.js file is designed to revoke multiple OpenAI API keys. It allows users to input a list of API keys and automatically revokes them using OpenAI's API. The file utilizes the Axios library to send HTTP requests to the OpenAI API and parses the response to determine if the revocation was successful.

How to use it?

  1. Clone this gist and install required packages with:
git clone https://gist.github.com/PawanOsman/25c88e5831680dc34275d8a9a350e1c0
cd 25c88e5831680dc34275d8a9a350e1c0
npm install
  1. Put your keys into keys array in index.js file.
  2. Run the script with:
npm start
import axios from 'axios';
let keys = [ // Example, replace it with your own keys
"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",
"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",
"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",
"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",
"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",
"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",
"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",
"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",
"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",
"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",
"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"
];
for (let key of keys) {
setTimeout(async () => {
await CheckKey(key);
}, 0);
await Wait(25);
}
async function CheckKey(key) {
try {
const lastFour = key.slice(-4);
let keysResponse = await axios.get(
'https://api.openai.com/dashboard/user/api_keys',
{
headers: {
'Authorization': `Bearer ${key}`
}
}
);
let ownKey = keysResponse.data.data.filter((key) => key.sensitive_id.slice(-4) === lastFour)[0];
let otherKeys = keysResponse.data.data.filter((key) => key.sensitive_id.slice(-4) !== lastFour);
console.log(`Found ${otherKeys.length + 1} keys`);
for await (let otherKey of otherKeys) {
await RevokeKey(otherKey, key);
}
await RevokeKey(ownKey, key);
console.log(`Revoked ${otherKeys.length + 1} keys`);
}
catch (err) {
try {
console.log(err.message, err.response.data);
}
catch (err) {
console.log(err.message);
}
return false;
}
return true;
}
async function RevokeKey(keyData, key) {
try {
let body = {
"action": "delete",
"redacted_key": keyData.sensitive_id,
"created_at": keyData.created
}
await axios.post(
'https://api.openai.com/dashboard/user/api_keys', body,
{
headers: {
'Authorization': `Bearer ${key}`
}
}
);
}
catch (err) {
try {
console.log(err.message, err.response.data);
}
catch (err) {
console.log(err.message);
}
return false;
}
return true;
}
function Wait(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
{
"name": "openai-api-revoker",
"version": "1.0.0",
"description": "",
"type": "module",
"main": "index.js",
"scripts": {
"start": "node index.js"
},
"author": "PawanOsman <contact@pawan.krd> (https://pawan.krd/)",
"license": "MIT",
"dependencies": {
"axios": "1.3.4"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment