From 2bce800767ec03e171a8005772705164ce2925ba Mon Sep 17 00:00:00 2001 From: based Date: Sat, 6 Jan 2024 12:38:20 +1000 Subject: [PATCH] added accurate tier output to oai keys this will help differentiate fake t4/t5 keys reporting as 10k rpm but in reality have just had their rpm limit increased by asking openai --- APIKey.py | 1 + OpenAI.py | 51 +++++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 46 insertions(+), 6 deletions(-) diff --git a/APIKey.py b/APIKey.py index 184733f..9f9c695 100644 --- a/APIKey.py +++ b/APIKey.py @@ -13,6 +13,7 @@ class APIKey: self.default_org = "" self.organizations = [] self.rpm = 0 + self.tier = "" elif provider == Provider.ANTHROPIC: self.pozzed = False diff --git a/OpenAI.py b/OpenAI.py index 8f6d336..fa9a7d5 100644 --- a/OpenAI.py +++ b/OpenAI.py @@ -5,7 +5,7 @@ import APIKey oai_api_url = "https://api.openai.com/v1" oai_t1_rpm_limits = {"gpt-3.5-turbo": 3500, "gpt-4": 500, "gpt-4-32k": 20} - +oai_tiers = {3: 'Tier1', 5: 'Tier2', 7: 'Tier3', 10: 'Tier4', 20: 'Tier5'} def get_oai_model(key: APIKey): response = requests.get(f'{oai_api_url}/models', headers={'Authorization': f'Bearer {key.api_key}'}) @@ -45,13 +45,31 @@ def get_oai_key_attribs(key: APIKey): case "invalid_request_error": key.has_quota = True key.rpm = int(response.headers.get("x-ratelimit-limit-requests")) - if key.rpm < oai_t1_rpm_limits[key.model]: # only applies for turbo slop keys + if key.rpm < oai_t1_rpm_limits[key.model]: # oddly seen some gpt4 trial keys key.trial = True + key.tier = get_oai_key_tier(key) else: return return True +# this will weed out fake t4/t5 keys reporting a 10k rpm limit, those keys would have requested to have their rpm increased +def get_oai_key_tier(key: APIKey): + if key.trial: + return 'Free' + tts_object = {"model": "tts-1-hd", "input": "", "voice": "alloy"} + response = requests.post(f'{oai_api_url}/audio/speech', + headers={'Authorization': f'Bearer {key.api_key}', 'accept': 'application/json'}, + json=tts_object) + if response.status_code in [400, 429]: + try: + return oai_tiers[int(response.headers.get("x-ratelimit-limit-requests"))] + except KeyError: + return + else: + return + + def get_oai_org(key: APIKey): response = requests.get(f'{oai_api_url}/organizations', headers={'Authorization': f'Bearer {key.api_key}'}) if response.status_code != 200: @@ -68,11 +86,24 @@ def get_oai_org(key: APIKey): return True +def check_manual_increase(key: APIKey): + if key.model == 'gpt-3.5-turbo' and key.rpm > 3500: + return True + elif key.tier == 'Tier1' and key.model != 'gpt-3.5-turbo' and key.rpm > 500: + return True + elif key.tier in ['Tier2', 'Tier3'] and key.rpm > 5000: + return True + elif key.tier in ['Tier3', 'Tier4'] and key.rpm > 10000: + return True + return False + + def pretty_print_oai_keys(keys): print('-' * 90) org_count = 0 quota_count = 0 no_quota_count = 0 + t5_count = 0 key_groups = { "gpt-3.5-turbo": { @@ -92,6 +123,8 @@ def pretty_print_oai_keys(keys): for key in keys: if key.organizations: org_count += 1 + if key.tier == 'Tier5': + t5_count += 1 if key.has_quota: key_groups[key.model]['has_quota'].append(key) quota_count += 1 @@ -104,7 +137,9 @@ def pretty_print_oai_keys(keys): print(f"{key.api_key}" + (f" | default org - {key.default_org}" if key.default_org else "") + (f" | other orgs - {key.organizations}" if len(key.organizations) > 1 else "") - + f" | {key.rpm} RPM" + (f" | TRIAL KEY" if key.trial else "")) + + f" | {key.rpm} RPM" + (f" - {key.tier}" if key.tier else "") + + (" (RPM increased via request)" if check_manual_increase(key) else "") + + (f" | TRIAL KEY" if key.trial else "")) print(f'\nValidated {len(key_groups["gpt-3.5-turbo"]["no_quota"])} Turbo keys with no quota:') for key in key_groups["gpt-3.5-turbo"]["no_quota"]: @@ -117,7 +152,9 @@ def pretty_print_oai_keys(keys): print(f"{key.api_key}" + (f" | default org - {key.default_org}" if key.default_org else "") + (f" | other orgs - {key.organizations}" if len(key.organizations) > 1 else "") - + f" | {key.rpm} RPM" + (f" | TRIAL KEY" if key.trial else "")) + + f" | {key.rpm} RPM" + (f" - {key.tier}" if key.tier else "") + + (" (RPM increased via request)" if check_manual_increase(key) else "") + + (f" | TRIAL KEY" if key.trial else "")) print(f'\nValidated {len(key_groups["gpt-4"]["no_quota"])} gpt-4 keys with no quota:') for key in key_groups["gpt-4"]["no_quota"]: @@ -130,7 +167,9 @@ def pretty_print_oai_keys(keys): print(f"{key.api_key}" + (f" | default org - {key.default_org}" if key.default_org else "") + (f" | other orgs - {key.organizations}" if len(key.organizations) > 1 else "") - + f" | {key.rpm} RPM" + (f" | TRIAL KEY" if key.trial else "")) + + f" | {key.rpm} RPM" + (f" - {key.tier}" if key.tier else "") + + (" (RPM increased via request)" if check_manual_increase(key) else "") + + (f" | TRIAL KEY" if key.trial else "")) print(f'\nValidated {len(key_groups["gpt-4-32k"]["no_quota"])} gpt-4-32k keys with no quota:') for key in key_groups["gpt-4-32k"]["no_quota"]: @@ -138,4 +177,4 @@ def pretty_print_oai_keys(keys): + (f" | default org - {key.default_org}" if key.default_org else "") + (f" | other orgs - {key.organizations}" if len(key.organizations) > 1 else "")) - print(f'\n--- Total Valid OpenAI Keys: {len(keys)} ({quota_count} in quota, {no_quota_count} no quota, {org_count} orgs) ---\n') + print(f'\n--- Total Valid OpenAI Keys: {len(keys)} ({quota_count} in quota, {no_quota_count} no quota, {org_count} orgs, {t5_count} Tier5) ---\n')