File size: 5,051 Bytes
98c28c1
48142c9
077f8e0
 
 
 
 
 
 
 
a665f3a
077f8e0
98c28c1
18adb0b
a665f3a
 
 
91a1375
a665f3a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
04ec5d2
077f8e0
 
 
 
 
 
 
 
 
 
04ec5d2
a665f3a
98c28c1
 
 
 
 
077f8e0
0606965
077f8e0
98c28c1
077f8e0
18adb0b
077f8e0
 
 
 
 
 
18adb0b
077f8e0
98c28c1
 
077f8e0
 
a665f3a
077f8e0
 
 
 
 
 
 
 
 
 
 
98c28c1
 
 
 
077f8e0
 
 
 
 
 
 
 
 
98c28c1
077f8e0
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
import gradio as gr
import requests, re
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, not_supported
)

async def sort_key(key, rate_limit, claude_model):
    """
    Check a single API key and return its info dict.
    """
    _key = key.strip()

    # OpenRouter
    if re.match(r"^sk-or-v1-[a-z0-9]{64}$", _key):    
        return get_key_openrouter_info(_key)
    # Anthropic Claude
    if (re.match(r"^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(r"^sk-[A-Za-z0-9]{86}$", _key))):
        return await get_key_ant_info(_key, rate_limit, claude_model)
    # Stability AI
    if re.match(r"^sk-[A-Za-z0-9]{48}$", _key) and len(_key) == 51 and 'T3BlbkFJ' not in _key:
        return get_key_stability_info(_key)
    # Deepseek
    if re.match(r"^sk-[a-f0-9]{32}$", _key):
        return get_key_deepseek_info(_key)
    # OpenAI
    if _key.startswith("sk-"):
        return get_key_oai_info(_key)
    # Google Gemini
    if _key.startswith("AIzaSy"):
        return get_key_gemini_info(_key)
    # NovelAI
    if _key.startswith("pst-"):
        return get_key_nai_info(_key)
    # Replicate
    if ((_key.startswith("r8_") and len(_key) == 40)
        or (_key.islower() and len(_key) == 40)):
        return get_key_replicate_info(_key)
    # xAI Grok
    if _key.startswith("xai-"):
        return get_key_xai_info(_key)
    # Azure OpenAI
    if len(_key.split(':')) == 2 and _key.split(':')[1].islower() and len(_key.split(':')[1]) == 32:
        endpoint, api_key = _key.split(':')
        return get_key_azure_info(f"{endpoint}.openai.azure.com", api_key)
    if "openai.azure.com" in _key:
        endpoint, api_key = _key.split(';')
        return get_key_azure_info(endpoint, api_key)
    # AWS
    if _key.startswith("AKIA") and len(_key.split(':')[0]) == 20 and _key.split(':')[0].isupper():
        return await get_key_aws_info(_key)
    # ElevenLabs
    if re.match(r"^[a-f0-9]{32}$", _key) or re.match(r"^sk_[a-f0-9]{48}$", _key):
        return get_key_elevenlabs_info(_key)
    # Mistral AI
    if re.match(r"^[A-Za-z0-9]{32}$", _key):
        return get_key_mistral_info(_key)
    # Groq
    if re.match(r"^gsk_[A-Za-z0-9]{20}WGdyb3FY[A-Za-z0-9]{24}$", _key):
        return get_key_groq_info(_key)
    # GCP Anthropic
    if re.match(r"[\w\-]+:[\w\-@\.]+:[\w\-]+:.+", _key):
        return await get_key_gcp_info(_key, 0)
    if re.match(r"[\w\-]+:[\w\-@\.]+:.+\\n", _key):
        return await get_key_gcp_info(_key, 1)

    # Fallback for unsupported formats
    return not_supported(_key)

async def sort_keys(keys_text, rate_limit, claude_model):
    """
    Split input by newline and lookup each key in turn.
    Returns a mapping from each key to its info dict.
    """
    keys = [k.strip() for k in keys_text.splitlines() if k.strip()]
    results = {}
    for k in keys:
        results[k] = await sort_key(k, rate_limit, claude_model)
    return results


def clear_inputs(text):
    return ""

with gr.Blocks() as demo:
    gr.Markdown('''
    # Multi-Key API Key Status Checker

    Enter one API key per line; this tool will check each in turn.
    ''')

    claude_options = [
        'claude-3-haiku-20240307',
        'claude-3-sonnet-20240229',
        'claude-3-opus-20240229',
        'claude-3-5-sonnet-20240620',
        'claude-3-5-sonnet-20241022',
        'claude-3-5-haiku-20241022'
    ]

    with gr.Row():
        with gr.Column():
            key_input = gr.Textbox(
                lines=5,
                placeholder="sk-... or AKIA...",
                label="API Keys (one per line)"
            )
            claude_model = gr.Dropdown(
                claude_options,
                value="claude-3-haiku-20240307",
                label="Claude API model",
                info="Model for filter_response and concurrent rate check"
            )
            rate_limit = gr.Checkbox(
                label="Check concurrent rate limit (Anthropic Claude)"
            )
            with gr.Row():
                clear_button = gr.Button("Clear")
                submit_button = gr.Button("Submit", variant="primary")
        with gr.Column():
            info = gr.JSON(label="API Keys Information", open=True)

    clear_button.click(fn=clear_inputs, inputs=[key_input], outputs=[key_input])
    submit_button.click(
        fn=sort_keys,
        inputs=[key_input, rate_limit, claude_model],
        outputs=[info],
        api_name="sort_keys"
    )

demo.launch()