File size: 7,667 Bytes
98c28c1 73540fd 09091e6 0606965 98c28c1 73540fd 91a1375 1ad76f4 a0bd21f 0606965 a6df1a0 1ad76f4 a0bd21f 1ad76f4 0606965 1ad76f4 0606965 73540fd 1ad76f4 73540fd 98c28c1 09091e6 a0bd21f 550dfd0 98c28c1 beff183 049253f 9d3366b 58e0b0e 049253f beff183 98c28c1 09091e6 58e0b0e 049253f 58e0b0e beff183 98c28c1 73540fd a0bd21f 73540fd 98c28c1 a0bd21f 1ad76f4 a6df1a0 a0bd21f 1ad76f4 a6df1a0 1ad76f4 a0bd21f 0606965 a0bd21f 1ad76f4 0606965 1ad76f4 a0bd21f 98c28c1 0606965 a0bd21f 0606965 9784311 0606965 98c28c1 1ad76f4 98c28c1 0606965 98c28c1 73540fd 98c28c1 |
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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
import gradio as gr
import anthropic
import requests
from api_usage import get_subscription, check_key_availability, check_key_ant_availability, check_key_gemini_availability, check_key_azure_availability, get_azure_status, get_azure_deploy, check_key_mistral_availability, check_mistral_quota, check_key_replicate_availability, check_key_aws_availability
def sort_key(key):
_key = key.strip()
if _key.startswith("sk-ant-"):
return get_key_ant_info(_key)
elif _key.startswith("sk-"):
return get_key_oai_info(_key)
elif _key.startswith("AIzaSy"):
return get_key_gemini_info(_key)
elif (_key.startswith("r8_") and len(_key) == 40) or (_key.islower() and len(_key) == 40):
return get_key_replicate_info(_key)
elif len(_key.split(':')) == 2 and _key.split(':')[1].islower() and len(_key.split(':')[1]) == 32 and "openai.azure.com" not in _key.split(':')[1]:
endpoint = f"{_key.split(':')[0]}.openai.azure.com"
api_key = _key.split(':')[1]
return get_key_azure_info(endpoint, api_key)
elif "openai.azure.com" in _key.split(';')[0]:
endpoint = _key.split(';')[0]
api_key = _key.split(';')[1]
return get_key_azure_info(endpoint, api_key)
elif _key.startswith("AKIA") and len(_key.split(':')[0]) == 20 and _key.split(':')[0].isupper():
return get_key_aws_info(_key)
elif len(_key) == 32:
return get_key_mistral_info(_key)
else:
return not_supported(_key)
def get_key_oai_info(key):
# Return a dictionary containing key information
session = requests.Session()
key_avai = check_key_availability(session, key)
info_dict = {#"account_name": "",
"key_type": "OpenAI",
"key_availability": True if key_avai else False,
"gpt4_availability": "",
"gpt4_32k_availability": "",
"default_org": "",
"org_description": "",
"organization": "",
"models": "",
"requests_per_minute": "",
"tokens_per_minute": "",
#"tokens_per_minute_left": "",
"quota": ""}
if key_avai:
info = get_subscription(key, session, key_avai)
info_dict["gpt4_availability"] = info["has_gpt4"]
info_dict["gpt4_32k_availability"] = info["has_gpt4_32k"]
info_dict["default_org"] = info["default_org"]
info_dict["org_description"] = info["org_description"]
info_dict["organization"] = info["organization"]
info_dict["models"] = info["models"]
info_dict["requests_per_minute"] = info["rpm"]
info_dict["tokens_per_minute"] = info["tpm"]
info_dict["quota"] = info["quota"]
return info_dict
def get_key_ant_info(key):
# Return a dictionary containing key information
ant = anthropic.Anthropic(api_key=key)
key_avai = check_key_ant_availability(ant)
info_dict = {#"account_name": "",
"key_type": "Anthropic Claude",
"key_availability": key_avai[0],
"status": key_avai[1],
"filter_response": key_avai[2]}
return info_dict
def get_key_gemini_info(key):
key_avai = check_key_gemini_availability(key)
info_dict = {#"account_name": "",
"key_type": "Google Gemini",
"key_availability": key_avai[0],
"models": key_avai[1]}
return info_dict
def get_key_gemini_info(key):
key_avai = check_key_gemini_availability(key)
info_dict = {#"account_name": "",
"key_type": "Google Gemini",
"key_availability": key_avai[0],
"models": key_avai[1]}
return info_dict
def get_key_azure_info(endpoint, api_key):
key_avai = check_key_azure_availability(endpoint, api_key)
info_dict = {#"account_name": "",
"key_type": "Microsoft Azure OpenAI",
"key_availability": key_avai[0],
"gpt35_availability": "",
"gpt4_availability": "",
"gpt4_turbo_availability": "",
"gpt4_32k_availability": "",
"moderation_status": "",
"models": "",
"deployments": ""}
if key_avai[0]:
azure_deploy = get_azure_deploy(endpoint, api_key)
status = get_azure_status(endpoint, api_key, azure_deploy)
info_dict["gpt35_availability"] = status[1]
info_dict["gpt4_availability"] = status[2]
info_dict["gpt4_turbo_availability"] = status[3]
info_dict["gpt4_32k_availability"] = status[4]
info_dict["moderation_status"] = status[0]
info_dict["models"] = key_avai[1]
info_dict["deployments"] = azure_deploy
return info_dict
def get_key_mistral_info(key):
key_avai = check_key_mistral_availability(key)
info_dict = {#"account_name": "",
"key_type": "Mistral AI",
"key_availability": key_avai,
"has_quota": ""}
if key_avai:
info_dict['has_quota'] = check_mistral_quota(key)
return info_dict
def get_key_replicate_info(key):
key_avai = check_key_replicate_availability(key)
info_dict = {#"account_name": "",
"key_type": "Replicate",
"key_availability": key_avai[0],
"account_name": "",
"type": "",
"hardware_available": ""}
if key_avai[0]:
info_dict['account_name'] = key_avai[1]['username']
info_dict['type'] = key_avai[1]['type']
info_dict['hardware_available'] = key_avai[2]
return info_dict
def get_key_aws_info(key):
key_avai = check_key_aws_availability(key)
info_dict = {#"account_name": "",
"key_type": "Amazon AWS Claude",
"key_availability": key_avai[0],
"username": "",
"root": "",
"admin": "",
"quarantine": "",
"claude_enabled_region": key_avai[5],
"cost_and_usage": ""}
if key_avai[0]:
info_dict['username'] = key_avai[1]
info_dict['root'] = key_avai[2]
info_dict['admin'] = key_avai[3]
info_dict['quarantine'] = key_avai[4]
info_dict['claude_enabled_region'] = key_avai[5]
info_dict['cost_and_usage'] = key_avai[6]
return info_dict
def not_supported(key):
info_dict = {#"account_name": "",
"key_type": "Not supported",
"status": ""}
return info_dict
def clear_inputs(text):
return ""
with gr.Blocks() as demo:
gr.Markdown('''
# OpenAI/Anthropic/Gemini/Azure/Mistral/Replicate/AWS Claude API Key Status Checker
*(Based on shaocongma, CncAnon1 and Drago key checkers)*
AWS credential's format: AWS_ACCESS_KEY_ID:AWS_SECRET_ACCESS_KEY (root might not be accurate)
Azure endpoint's format: YOUR_RESOURCE_NAME:YOUR_API_KEY or (https://)YOUR_RESOURCE_NAME.openai.azure.com;YOUR_API_KEY
''')
with gr.Row():
with gr.Column():
key = gr.Textbox(lines=1, max_lines=1, label="API Key")
with gr.Row():
clear_button = gr.Button("Clear")
submit_button = gr.Button("Submit", variant="primary")
with gr.Column():
info = gr.JSON(label="API Key Information")
clear_button.click(fn=clear_inputs, inputs=[key], outputs=[key])
submit_button.click(fn=sort_key, inputs=[key], outputs=[info], api_name="sort_key")
demo.launch() |