prxyasd commited on
Commit
077f8e0
·
verified ·
1 Parent(s): 5bda982

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +55 -360
app.py CHANGED
@@ -1,384 +1,79 @@
1
  import gradio as gr
2
  import requests, re
3
- from api_usage import get_subscription, check_key_availability, get_orgs_me, check_key_ant_availability, check_ant_rate_limit, 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, check_key_or_availability, check_key_or_limits, check_gcp_anthropic, check_groq_status, check_nai_status, check_elevenlabs_status, check_xai_status, check_stability_status, check_deepseek_status
 
 
 
 
 
 
 
 
 
4
 
5
  async def sort_key(key, rate_limit, claude_model):
6
  _key = key.strip()
7
-
8
- if re.match(re.compile("sk-or-v1-[a-z0-9]{64}"), _key):
9
- return get_key_openrouter_info(_key)
10
-
11
- if re.match(re.compile("sk-ant-api03-[a-zA-Z0-9\-_]{93}AA"), _key) or (_key.startswith("sk-ant-") and len(_key) == 93) or (len(_key) == 89 and re.match(re.compile("sk-[a-zA-Z0-9]{86}"), _key)):
12
- return await get_key_ant_info(_key, rate_limit, claude_model)
13
-
14
- if re.match(re.compile(r"sk-[a-zA-Z0-9]{48}"), _key) and len(_key) == 51 and 'T3BlbkFJ' not in _key:
15
- return get_key_stability_info(_key)
16
-
17
- if re.match(re.compile(r"sk-[a-f0-9]{32}"), _key):
18
- return get_key_deepseek_info(_key)
19
-
20
- if _key.startswith("sk-"):
21
- return get_key_oai_info(_key)
22
-
23
- if _key.startswith("AIzaSy"):
24
- return get_key_gemini_info(_key)
25
-
26
- if _key.startswith("pst-"):
27
- return get_key_nai_info(_key)
28
-
29
- if (_key.startswith("r8_") and len(_key) == 40) or (_key.islower() and len(_key) == 40):
30
- return get_key_replicate_info(_key)
31
-
32
- if _key.startswith("xai-"):
33
- return get_key_xai_info(_key)
34
-
35
- if len(_key.split(':')) == 2 and _key.split(':')[1].islower() and len(_key.split(':')[1]) == 32 and "openai.azure.com" not in _key.split(':')[1]:
36
- endpoint = f"{_key.split(':')[0]}.openai.azure.com"
37
- api_key = _key.split(':')[1]
38
- return get_key_azure_info(endpoint, api_key)
39
-
40
- if "openai.azure.com" in _key.split(';')[0]:
41
- endpoint = _key.split(';')[0]
42
- api_key = _key.split(';')[1]
43
- return get_key_azure_info(endpoint, api_key)
44
-
45
- if _key.startswith("AKIA") and len(_key.split(':')[0]) == 20 and _key.split(':')[0].isupper():
46
- return await get_key_aws_info(_key)
47
-
48
- if re.match(re.compile(r"[a-f0-9]{32}"), _key) or re.match(re.compile(r"sk_[a-f0-9]{48}"), _key):
49
- return get_key_elevenlabs_info(_key)
50
-
51
- if re.match(re.compile(r"[a-zA-Z0-9]{32}"), _key):
52
- return get_key_mistral_info(_key)
53
-
54
- if re.match(re.compile(r"gsk_[a-zA-Z0-9]{20}WGdyb3FY[a-zA-Z0-9]{24}"), _key):
55
- return get_key_groq_info(_key)
56
-
57
- if re.match(re.compile(r"[\w\-]+:[\w\-@\.]+:[\w-]+:.+"), _key): # 0: refresh token
58
- return await get_key_gcp_info(_key, 0)
59
-
60
- if re.match(re.compile(r"[\w\-]+:[\w\-@\.]+:.+\\n"), _key): # 1: service account
61
- return await get_key_gcp_info(_key, 1)
62
-
63
- return not_supported(_key)
64
-
65
- def get_key_oai_info(key):
66
- # Return a dictionary containing key information
67
- session = requests.Session()
68
-
69
- status, org_data = check_key_availability(session, key)
70
-
71
- info_dict = {
72
- "key_type": "OpenAI",
73
- "key_availability": True if status else False,
74
- "gpt4_availability": "",
75
- "gpt4_32k_availability": "",
76
- "default_org": "",
77
- "org_description": "",
78
- "organization": "",
79
- "models": "",
80
- "requests_per_minute": "",
81
- "tokens_per_minute": "",
82
- "quota": "",
83
- "all_models": ""
84
- }
85
-
86
- if not status:
87
- return info_dict
88
-
89
- if status == 403:
90
- status_me, orgs_me = get_orgs_me(session, key)
91
- if status_me == 200:
92
- org_data = orgs_me
93
-
94
- subscription_info = get_subscription(key, session, org_data)
95
-
96
- # Update the info_dict with subscription details
97
- info_dict.update({
98
- "gpt4_availability": subscription_info["has_gpt4"],
99
- "gpt4_32k_availability": subscription_info["has_gpt4_32k"],
100
- "default_org": subscription_info["default_org"],
101
- "org_description": subscription_info["org_description"],
102
- "organization": subscription_info["organization"],
103
- "models": subscription_info["models"],
104
- "requests_per_minute": subscription_info["rpm"],
105
- "tokens_per_minute": subscription_info["tpm"],
106
- "quota": subscription_info["quota"],
107
- "all_models": subscription_info["all_models"]
108
- })
109
-
110
- return info_dict
111
-
112
- async def get_key_ant_info(key, rate_limit, claude_model):
113
- # Return a dictionary containing key information
114
- key_avai = await check_key_ant_availability(key, claude_model)
115
- info_dict = {#"account_name": "",
116
- "key_type": "Anthropic Claude",
117
- "key_availability": key_avai[0],
118
- "status": "",
119
- "filter_response": "",
120
- "requests_per_minute": "",
121
- "tokens_per_minute": "",
122
- "tokens_input_per_minute": "",
123
- "tokens_output_per_minute": "",
124
- "tier": "",
125
- "concurrent_rate_limit": "",
126
- "models": ""}
127
-
128
- info_dict["status"] = key_avai[1]
129
- info_dict["filter_response"] = key_avai[2]
130
- info_dict["requests_per_minute"] = key_avai[3] + ("" if key_avai[3] == "" else f" ({key_avai[4]} left)")
131
- info_dict["tokens_per_minute"] = key_avai[5] + ("" if key_avai[5] == "" else f" ({key_avai[6]} left)")
132
- info_dict["tokens_input_per_minute"] = key_avai[8] + ("" if key_avai[8] == "" else f" ({key_avai[9]} left)")
133
- info_dict["tokens_output_per_minute"] = key_avai[10] + ("" if key_avai[10] == "" else f" ({key_avai[11]} left)")
134
- info_dict["tier"] = key_avai[7]
135
- info_dict["models"] = key_avai[12]
136
-
137
- if rate_limit:
138
- rate = await check_ant_rate_limit(key, claude_model)
139
- info_dict["concurrent_rate_limit"] = rate
140
-
141
- return info_dict
142
-
143
- def get_key_gemini_info(key):
144
- key_avai = check_key_gemini_availability(key)
145
- info_dict = {#"account_name": "",
146
- "key_type": "Google Gemini",
147
- "key_availability": key_avai[0],
148
- "status": key_avai[1],
149
- "models": key_avai[2]}
150
- return info_dict
151
-
152
- def get_key_azure_info(endpoint, api_key):
153
- key_avai = check_key_azure_availability(endpoint, api_key)
154
- info_dict = {#"account_name": "",
155
- "key_type": "Microsoft Azure OpenAI",
156
- "key_availability": key_avai[0],
157
- "gpt35_availability": "",
158
- "gpt4_availability": "",
159
- "gpt4_32k_availability": "",
160
- "dall_e_3_availability": "",
161
- "moderation_status": "",
162
- "models": "",
163
- "deployments": ""}
164
- if key_avai[0]:
165
- azure_deploy = get_azure_deploy(endpoint, api_key)
166
- status = get_azure_status(endpoint, api_key, azure_deploy)
167
- info_dict["gpt35_availability"] = status[1]
168
- info_dict["gpt4_availability"] = status[2]
169
- info_dict["gpt4_32k_availability"] = status[3]
170
- info_dict["dall_e_3_availability"] = status[4]
171
- info_dict["moderation_status"] = status[0]
172
- info_dict["models"] = key_avai[1]
173
- info_dict["deployments"] = azure_deploy
174
- return info_dict
175
-
176
- def get_key_mistral_info(key):
177
- key_avai = check_key_mistral_availability(key)
178
- info_dict = {#"account_name": "",
179
- "key_type": "Mistral AI",
180
- "key_availability": True if key_avai else False,
181
- "has_quota": "",
182
- "limits": "",
183
- "models": ""}
184
- if key_avai:
185
- quota_info = check_mistral_quota(key)
186
- info_dict['has_quota'] = quota_info[0]
187
- if quota_info[1]:
188
- info_dict['limits'] = quota_info[1]
189
- info_dict['models'] = key_avai
190
- return info_dict
191
-
192
- def get_key_replicate_info(key):
193
- key_avai = check_key_replicate_availability(key)
194
- info_dict = {#"account_name": "",
195
- "key_type": "Replicate",
196
- "key_availability": key_avai[0],
197
- "account_name": "",
198
- "type": "",
199
- "has_quota": "",
200
- "hardware_available": ""}
201
- if key_avai[0]:
202
- info_dict['account_name'] = key_avai[1]['username']
203
- info_dict['type'] = key_avai[1]['type']
204
- info_dict['has_quota'] = key_avai[2]
205
- info_dict['hardware_available'] = key_avai[3]
206
- return info_dict
207
-
208
- async def get_key_aws_info(key):
209
- key_avai = await check_key_aws_availability(key)
210
- info_dict = {#"account_name": "",
211
- "key_type": "Amazon AWS Claude",
212
- "key_availability": key_avai[0],
213
- "username": "",
214
- "root": "",
215
- "admin": "",
216
- "quarantine": "",
217
- "iam_full_access": "",
218
- "iam_user_change_password": "",
219
- "aws_bedrock_full_access": "",
220
- "enabled_region": "",
221
- "models_usage": "",
222
- "cost_and_usage": key_avai[1]}
223
- if key_avai[0]:
224
- info_dict['username'] = key_avai[1]
225
- info_dict['root'] = key_avai[2]
226
- info_dict['admin'] = key_avai[3]
227
- info_dict['quarantine'] = key_avai[4]
228
- info_dict['iam_full_access'] = key_avai[5]
229
- info_dict['iam_user_change_password'] = key_avai[6]
230
- info_dict['aws_bedrock_full_access'] = key_avai[7]
231
- info_dict['enabled_region'] = key_avai[8]
232
- info_dict['models_usage'] = key_avai[9]
233
- info_dict['cost_and_usage'] = key_avai[10]
234
- return info_dict
235
-
236
- def get_key_openrouter_info(key):
237
- key_avai = check_key_or_availability(key)
238
- info_dict = {#"account_name": "",
239
- "key_type": "OpenRouter",
240
- "key_availability": key_avai[0],
241
- "is_free_tier": "",
242
- "usage": "",
243
- "balance": "",
244
- "limit": "",
245
- "limit_remaining": "",
246
- "rate_limit_per_minite": "",
247
- "4_turbo_per_request_tokens_limit": "",
248
- "sonnet_per_request_tokens_limit": "",
249
- "opus_per_request_tokens_limit": ""}
250
- if key_avai[0]:
251
- models_info = check_key_or_limits(key)
252
- info_dict['is_free_tier'] = key_avai[1]['is_free_tier']
253
- info_dict['limit'] = key_avai[1]['limit']
254
- info_dict['limit_remaining'] = key_avai[1]['limit_remaining']
255
- info_dict['usage'] = f"${format(key_avai[1]['usage'], '.4f')}"
256
- info_dict['balance'] = f"${format(models_info[0], '.4f')}" if models_info[0] else f"${key_avai[2]/60} (estimated)"
257
- info_dict['rate_limit_per_minite'] = key_avai[2]
258
- info_dict['4_turbo_per_request_tokens_limit'] = models_info[1]['openai/gpt-4o']
259
- info_dict['sonnet_per_request_tokens_limit'] = models_info[1]['anthropic/claude-3.5-sonnet:beta']
260
- info_dict['opus_per_request_tokens_limit'] = models_info[1]['anthropic/claude-3-opus:beta']
261
- else:
262
- info_dict['usage'] = key_avai[1]
263
- return info_dict
264
-
265
- async def get_key_gcp_info(key, type):
266
- key_avai = await check_gcp_anthropic(key, type)
267
- info_dict = {#"account_name": "",
268
- "key_type": "Vertex AI (GCP)",
269
- "key_availability": key_avai[0],
270
- "status": "",
271
- "enabled_region": ""}
272
- if key_avai[0]:
273
- info_dict['enabled_region'] = key_avai[2]
274
- else:
275
- info_dict['status'] = key_avai[1]
276
- return info_dict
277
-
278
- def get_key_groq_info(key):
279
- key_avai = check_groq_status(key)
280
- info_dict = {#"account_name": "",
281
- "key_type": "Groq",
282
- "key_availability": True if key_avai else False,
283
- "models": key_avai if key_avai else ""}
284
- return info_dict
285
-
286
- def get_key_nai_info(key):
287
- key_avai = check_nai_status(key)
288
- info_dict = {#"account_name": "",
289
- "key_type": "NovelAI",
290
- "key_availability": True if key_avai[0] else False,
291
- "user_info": key_avai[1] if key_avai[0] else ""}
292
- return info_dict
293
-
294
- def get_key_elevenlabs_info(key):
295
- key_avai = check_elevenlabs_status(key)
296
- info_dict = {#"account_name": "",
297
- "key_type": "ElevenLabs",
298
- "key_availability": key_avai[0],
299
- "user_info": key_avai[1],
300
- "voices_info": key_avai[2]}
301
  return info_dict
302
 
303
- def get_key_xai_info(key):
304
- key_avai = check_xai_status(key)
305
- info_dict = {#"account_name": "",
306
- "key_type": "xAI Grok",
307
- "key_availability": key_avai[0],
308
- "key_status": "",
309
- "models": ""}
310
- if key_avai[0]:
311
- info_dict['key_status'] = key_avai[1]
312
- info_dict['models'] = key_avai[2]
313
- return info_dict
314
-
315
- def get_key_stability_info(key):
316
- key_avai = check_stability_status(key)
317
- info_dict = {#"account_name": "",
318
- "key_type": "Stability AI",
319
- "key_availability": key_avai[0],
320
- "account_info": "",
321
- "credits": "",
322
- "models": ""}
323
- if key_avai[0]:
324
- info_dict['account_info'] = key_avai[1]
325
- info_dict['credits'] = key_avai[2]
326
- info_dict['models'] = key_avai[3]
327
- return info_dict
328
-
329
- def get_key_deepseek_info(key):
330
- key_avai = check_deepseek_status(key)
331
- info_dict = {#"account_name": "",
332
- "key_type": "deepseek",
333
- "key_availability": key_avai[0],
334
- "balance": "",
335
- "models": ""}
336
- if key_avai[0]:
337
- info_dict['models'] = key_avai[1]
338
- info_dict['balance'] = key_avai[2]
339
- return info_dict
340
 
341
- def not_supported(key):
342
- info_dict = {#"account_name": "",
343
- "key_type": "Not supported",
344
- "status": ""}
345
- return info_dict
346
-
347
  def clear_inputs(text):
348
  return ""
349
 
350
  with gr.Blocks() as demo:
351
  gr.Markdown('''
352
- # OpenAI/Anthropic/Gemini/Azure/Mistral/Replicate/AWS Claude/OpenRouter/Vertex AI(GCP Anthropic)/Groq/NovelAI/ElevenLabs/xAI/Stability/Deepseek API Key Status Checker
353
-
354
- *(Based on shaocongma, CncAnon1, su, Drago, kingbased key checkers)*
355
 
356
- AWS credential's format: AWS_ACCESS_KEY_ID:AWS_SECRET_ACCESS_KEY (root might not be accurate)
357
-
358
- Azure endpoint's format: YOUR_RESOURCE_NAME:YOUR_API_KEY or (https://)YOUR_RESOURCE_NAME.openai.azure.com;YOUR_API_KEY
359
-
360
- GCP format: PROJECT_ID:CLIENT_EMAIL:PRIVATE_KEY (including \\n)
361
- | or refresh token: PROJECT_ID:CLIENT_ID:CLIENT_SECRET:REFRESH_TOKEN
362
  ''')
 
363
  claude_options = [
364
- 'claude-3-haiku-20240307',
365
- 'claude-3-sonnet-20240229',
366
- 'claude-3-opus-20240229',
367
- 'claude-3-5-sonnet-20240620',
368
- 'claude-3-5-sonnet-20241022',
369
- 'claude-3-5-haiku-20241022'
370
  ]
 
371
  with gr.Row():
372
  with gr.Column():
373
- key = gr.Textbox(lines=1, max_lines=5, label="API Key")
374
- claude_model = gr.Dropdown(claude_options, value="claude-3-haiku-20240307", label="Claude API model", info="model for filter_response and concurrent check")
375
- rate_limit = gr.Checkbox(label="Check concurrent rate limit (API Claude, experimental)")
 
 
 
 
 
 
 
 
 
 
 
376
  with gr.Row():
377
  clear_button = gr.Button("Clear")
378
  submit_button = gr.Button("Submit", variant="primary")
379
  with gr.Column():
380
- info = gr.JSON(label="API Key Information", open=True)
 
 
 
 
 
 
 
 
381
 
382
- clear_button.click(fn=clear_inputs, inputs=[key], outputs=[key])
383
- submit_button.click(fn=sort_key, inputs=[key, rate_limit, claude_model], outputs=[info], api_name="sort_key")
384
- demo.launch()
 
1
  import gradio as gr
2
  import requests, re
3
+ from api_usage import (
4
+ get_subscription, check_key_availability, get_orgs_me,
5
+ check_key_ant_availability, check_ant_rate_limit, check_key_gemini_availability,
6
+ check_key_azure_availability, get_azure_status, get_azure_deploy,
7
+ check_key_mistral_availability, check_mistral_quota, check_key_replicate_availability,
8
+ check_key_aws_availability, check_key_or_availability, check_key_or_limits,
9
+ check_gcp_anthropic, check_groq_status, check_nai_status,
10
+ check_elevenlabs_status, check_xai_status, check_stability_status,
11
+ check_deepseek_status
12
+ )
13
 
14
  async def sort_key(key, rate_limit, claude_model):
15
  _key = key.strip()
16
+ # (existing matching logic omitted for brevity...)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  return info_dict
18
 
19
+ async def sort_keys(keys_text, rate_limit, claude_model):
20
+ """
21
+ Split input by newline and lookup each key in turn.
22
+ Returns a mapping from each key to its info dict.
23
+ """
24
+ keys = [k.strip() for k in keys_text.splitlines() if k.strip()]
25
+ results = {}
26
+ for k in keys:
27
+ results[k] = await sort_key(k, rate_limit, claude_model)
28
+ return results
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
 
 
 
 
 
 
 
30
  def clear_inputs(text):
31
  return ""
32
 
33
  with gr.Blocks() as demo:
34
  gr.Markdown('''
35
+ # Multi-Key API Key Status Checker
 
 
36
 
37
+ Enter one API key per line; this tool will check each in turn.
 
 
 
 
 
38
  ''')
39
+
40
  claude_options = [
41
+ 'claude-3-haiku-20240307',
42
+ 'claude-3-sonnet-20240229',
43
+ 'claude-3-opus-20240229',
44
+ 'claude-3-5-sonnet-20240620',
45
+ 'claude-3-5-sonnet-20241022',
46
+ 'claude-3-5-haiku-20241022'
47
  ]
48
+
49
  with gr.Row():
50
  with gr.Column():
51
+ key_input = gr.Textbox(
52
+ lines=5,
53
+ placeholder="sk-... or AKIA...",
54
+ label="API Keys (one per line)"
55
+ )
56
+ claude_model = gr.Dropdown(
57
+ claude_options,
58
+ value="claude-3-haiku-20240307",
59
+ label="Claude API model",
60
+ info="Model for filter_response and concurrent rate check"
61
+ )
62
+ rate_limit = gr.Checkbox(
63
+ label="Check concurrent rate limit (Anthropic Claude)"
64
+ )
65
  with gr.Row():
66
  clear_button = gr.Button("Clear")
67
  submit_button = gr.Button("Submit", variant="primary")
68
  with gr.Column():
69
+ info = gr.JSON(label="API Keys Information", open=True)
70
+
71
+ clear_button.click(fn=clear_inputs, inputs=[key_input], outputs=[key_input])
72
+ submit_button.click(
73
+ fn=sort_keys,
74
+ inputs=[key_input, rate_limit, claude_model],
75
+ outputs=[info],
76
+ api_name="sort_keys"
77
+ )
78
 
79
+ demo.launch()