-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
1068 lines (957 loc) · 31.4 KB
/
main.go
File metadata and controls
1068 lines (957 loc) · 31.4 KB
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package main
import (
"bytes"
"encoding/json"
"flag"
"fmt"
"io"
"net/http"
"os"
"runtime/debug"
"strings"
"time"
)
var version = func() string {
if info, ok := debug.ReadBuildInfo(); ok && info.Main.Version != "" && info.Main.Version != "(devel)" {
return strings.TrimPrefix(info.Main.Version, "v")
}
return "dev"
}()
// ANSI colors
const (
colorReset = "\033[0m"
colorRed = "\033[31m"
colorGreen = "\033[32m"
colorYellow = "\033[33m"
colorBlue = "\033[34m"
colorCyan = "\033[36m"
colorBold = "\033[1m"
colorDim = "\033[2m"
)
func green(s string) string { return colorGreen + s + colorReset }
func red(s string) string { return colorRed + s + colorReset }
func yellow(s string) string { return colorYellow + s + colorReset }
func cyan(s string) string { return colorCyan + s + colorReset }
func bold(s string) string { return colorBold + s + colorReset }
func dim(s string) string { return colorDim + s + colorReset }
// ─── Provider detection ───────────────────────────────────────────────────────
type Provider string
const (
ProviderAnthropic Provider = "anthropic"
ProviderOpenAI Provider = "openai"
ProviderGemini Provider = "gemini"
ProviderCohere Provider = "cohere"
ProviderMistral Provider = "mistral"
ProviderGroq Provider = "groq"
ProviderTogether Provider = "together"
ProviderPerplexity Provider = "perplexity"
ProviderDeepSeek Provider = "deepseek"
ProviderXAI Provider = "xai"
ProviderHuggingFace Provider = "huggingface"
ProviderReplicate Provider = "replicate"
ProviderUnknown Provider = "unknown"
)
func detectProvider(key string) Provider {
switch {
case strings.HasPrefix(key, "sk-ant-"):
return ProviderAnthropic
case strings.HasPrefix(key, "sk-") && len(key) == 51:
return ProviderOpenAI
case strings.HasPrefix(key, "sk-proj-"):
return ProviderOpenAI
case strings.HasPrefix(key, "sk-or-"):
return ProviderOpenAI // OpenRouter uses same prefix pattern
case strings.HasPrefix(key, "AIzaSy"):
return ProviderGemini
case strings.HasPrefix(key, "sk-cohere-") || (len(key) == 40 && !strings.Contains(key, "-")):
return ProviderCohere
case strings.HasPrefix(key, "gsk_"):
return ProviderGroq
case strings.HasPrefix(key, "r8_"):
return ProviderReplicate
case strings.HasPrefix(key, "hf_"):
return ProviderHuggingFace
case strings.HasPrefix(key, "xai-"):
return ProviderXAI
case strings.HasPrefix(key, "pplx-"):
return ProviderPerplexity
case strings.HasPrefix(key, "together-") || strings.HasPrefix(key, "tgr_"):
return ProviderTogether
case strings.HasPrefix(key, "sk-") && len(key) > 51:
// OpenAI newer keys are longer
return ProviderOpenAI
default:
// Try length/entropy heuristics for Mistral, Cohere, DeepSeek
if len(key) == 32 {
return ProviderMistral
}
if len(key) == 64 {
return ProviderDeepSeek
}
return ProviderUnknown
}
}
// ─── Result types ─────────────────────────────────────────────────────────────
type Capability struct {
Name string
Available bool
Description string
}
type ValidationResult struct {
Provider Provider
Valid bool
Error string
Model string
OrgID string
Capabilities []Capability
RawDetails map[string]string
}
type jsonCapability struct {
Name string `json:"name"`
Available bool `json:"available"`
Description string `json:"description"`
}
type jsonResult struct {
Provider string `json:"provider"`
Valid bool `json:"valid"`
Error string `json:"error,omitempty"`
Model string `json:"model,omitempty"`
Capabilities []jsonCapability `json:"capabilities,omitempty"`
Details map[string]string `json:"details,omitempty"`
}
// ─── HTTP helpers ─────────────────────────────────────────────────────────────
var httpClient = &http.Client{Timeout: 15 * time.Second}
func doRequest(method, url string, headers map[string]string, body []byte) (int, []byte, error) {
var req *http.Request
var err error
if body != nil {
req, err = http.NewRequest(method, url, bytes.NewReader(body))
} else {
req, err = http.NewRequest(method, url, nil)
}
if err != nil {
return 0, nil, err
}
for k, v := range headers {
req.Header.Set(k, v)
}
resp, err := httpClient.Do(req)
if err != nil {
return 0, nil, err
}
defer resp.Body.Close()
b, err := io.ReadAll(resp.Body)
return resp.StatusCode, b, err
}
// ─── Validators ───────────────────────────────────────────────────────────────
func validateAnthropic(key string) ValidationResult {
result := ValidationResult{Provider: ProviderAnthropic}
// 1. Test basic API access with a minimal message
payload := map[string]interface{}{
"model": "claude-haiku-4-5-20251001",
"max_tokens": 1,
"messages": []map[string]string{{"role": "user", "content": "hi"}},
}
body, _ := json.Marshal(payload)
status, respBody, err := doRequest("POST", "https://api.anthropic.com/v1/messages", map[string]string{
"x-api-key": key,
"anthropic-version": "2023-06-01",
"content-type": "application/json",
}, body)
if err != nil {
result.Error = err.Error()
return result
}
if status == 401 || status == 403 {
result.Valid = false
var e map[string]interface{}
if json.Unmarshal(respBody, &e) == nil {
if errObj, ok := e["error"].(map[string]interface{}); ok {
result.Error = fmt.Sprintf("%v", errObj["message"])
}
}
return result
}
result.Valid = true
result.Model = "claude-haiku-4-5-20251001 (used for validation)"
// 2. Probe capabilities
// Chat / Messages API
result.Capabilities = append(result.Capabilities, Capability{
Name: "Messages API (chat)",
Available: true,
Description: "Send and receive chat messages",
})
// Streaming
streamPayload := map[string]interface{}{
"model": "claude-haiku-4-5-20251001",
"max_tokens": 1,
"stream": true,
"messages": []map[string]string{{"role": "user", "content": "hi"}},
}
streamBody, _ := json.Marshal(streamPayload)
sStatus, _, _ := doRequest("POST", "https://api.anthropic.com/v1/messages", map[string]string{
"x-api-key": key,
"anthropic-version": "2023-06-01",
"content-type": "application/json",
}, streamBody)
result.Capabilities = append(result.Capabilities, Capability{
Name: "Streaming",
Available: sStatus == 200,
Description: "Stream tokens in real-time",
})
// Files / Documents beta (claude-3.5 models)
docPayload := map[string]interface{}{
"model": "claude-sonnet-4-20250514",
"max_tokens": 1,
"messages": []map[string]string{{"role": "user", "content": "hi"}},
}
docBody, _ := json.Marshal(docPayload)
dStatus, _, _ := doRequest("POST", "https://api.anthropic.com/v1/messages", map[string]string{
"x-api-key": key,
"anthropic-version": "2023-06-01",
"content-type": "application/json",
}, docBody)
result.Capabilities = append(result.Capabilities, Capability{
Name: "Claude Sonnet 4 access",
Available: dStatus == 200,
Description: "Access to claude-sonnet-4-20250514",
})
// Opus
opusPayload := map[string]interface{}{
"model": "claude-opus-4-20250514",
"max_tokens": 1,
"messages": []map[string]string{{"role": "user", "content": "hi"}},
}
opusBody, _ := json.Marshal(opusPayload)
oStatus, _, _ := doRequest("POST", "https://api.anthropic.com/v1/messages", map[string]string{
"x-api-key": key,
"anthropic-version": "2023-06-01",
"content-type": "application/json",
}, opusBody)
result.Capabilities = append(result.Capabilities, Capability{
Name: "Claude Opus 4 access",
Available: oStatus == 200,
Description: "Access to claude-opus-4-20250514",
})
// Claude Code — uses the same API key but requires claude-sonnet-4 or opus-4
// Claude Code is a CLI tool authenticated via the same API key; if you can
// hit the models it uses, Claude Code will work with this key.
claudeCodeAvailable := dStatus == 200 || oStatus == 200
result.Capabilities = append(result.Capabilities, Capability{
Name: "Claude Code (CLI)",
Available: claudeCodeAvailable,
Description: "Run `claude` CLI — requires Sonnet 4 or Opus 4 access",
})
// Batch API
bStatus, _, _ := doRequest("GET", "https://api.anthropic.com/v1/messages/batches", map[string]string{
"x-api-key": key,
"anthropic-version": "2023-06-01",
}, nil)
result.Capabilities = append(result.Capabilities, Capability{
Name: "Batch API",
Available: bStatus == 200,
Description: "Asynchronous large-scale message processing",
})
// Files API (beta)
fStatus, _, _ := doRequest("GET", "https://api.anthropic.com/v1/files", map[string]string{
"x-api-key": key,
"anthropic-version": "2023-06-01",
"anthropic-beta": "files-api-2025-04-14",
}, nil)
result.Capabilities = append(result.Capabilities, Capability{
Name: "Files API (beta)",
Available: fStatus == 200,
Description: "Upload and manage files for use in messages",
})
return result
}
func validateOpenAI(key string) ValidationResult {
result := ValidationResult{Provider: ProviderOpenAI}
status, respBody, err := doRequest("GET", "https://api.openai.com/v1/models", map[string]string{
"Authorization": "Bearer " + key,
}, nil)
if err != nil {
result.Error = err.Error()
return result
}
if status == 401 {
result.Valid = false
var e map[string]interface{}
if json.Unmarshal(respBody, &e) == nil {
if errObj, ok := e["error"].(map[string]interface{}); ok {
result.Error = fmt.Sprintf("%v", errObj["message"])
}
}
return result
}
result.Valid = true
var modelsResp struct {
Data []struct {
ID string `json:"id"`
} `json:"data"`
}
json.Unmarshal(respBody, &modelsResp)
modelSet := map[string]bool{}
for _, m := range modelsResp.Data {
modelSet[m.ID] = true
}
check := func(name, model, desc string) {
result.Capabilities = append(result.Capabilities, Capability{
Name: name,
Available: modelSet[model],
Description: desc,
})
}
check("GPT-4o", "gpt-4o", "Latest multimodal GPT-4 model")
check("GPT-4o mini", "gpt-4o-mini", "Lightweight GPT-4o variant")
check("o1", "o1", "Reasoning model (o1)")
check("o3", "o3", "Advanced reasoning model (o3)")
check("GPT-4.1", "gpt-4.1", "GPT-4.1 model access")
// Embeddings
ePayload := map[string]interface{}{
"model": "text-embedding-3-small",
"input": "test",
}
eBody, _ := json.Marshal(ePayload)
eStatus, _, _ := doRequest("POST", "https://api.openai.com/v1/embeddings", map[string]string{
"Authorization": "Bearer " + key,
"Content-Type": "application/json",
}, eBody)
result.Capabilities = append(result.Capabilities, Capability{
Name: "Embeddings",
Available: eStatus == 200,
Description: "text-embedding-3-small/large",
})
// DALL-E
result.Capabilities = append(result.Capabilities, Capability{
Name: "DALL-E 3 (image gen)",
Available: modelSet["dall-e-3"],
Description: "Image generation via DALL-E 3",
})
// Whisper
result.Capabilities = append(result.Capabilities, Capability{
Name: "Whisper (speech-to-text)",
Available: modelSet["whisper-1"],
Description: "Audio transcription",
})
// TTS
result.Capabilities = append(result.Capabilities, Capability{
Name: "TTS (text-to-speech)",
Available: modelSet["tts-1"],
Description: "Text-to-speech synthesis",
})
// Assistants API
aStatus, _, _ := doRequest("GET", "https://api.openai.com/v1/assistants", map[string]string{
"Authorization": "Bearer " + key,
"OpenAI-Beta": "assistants=v2",
}, nil)
result.Capabilities = append(result.Capabilities, Capability{
Name: "Assistants API",
Available: aStatus == 200,
Description: "Stateful assistant threads with tools",
})
// Fine-tuning
ftStatus, _, _ := doRequest("GET", "https://api.openai.com/v1/fine_tuning/jobs", map[string]string{
"Authorization": "Bearer " + key,
}, nil)
result.Capabilities = append(result.Capabilities, Capability{
Name: "Fine-tuning",
Available: ftStatus == 200,
Description: "Custom model training",
})
// Org info
uStatus, uBody, _ := doRequest("GET", "https://api.openai.com/v1/organization/users", map[string]string{
"Authorization": "Bearer " + key,
}, nil)
if uStatus == 200 {
var orgResp map[string]interface{}
if json.Unmarshal(uBody, &orgResp) == nil {
result.RawDetails = map[string]string{"org_info": "accessible"}
}
}
return result
}
func validateGemini(key string) ValidationResult {
result := ValidationResult{Provider: ProviderGemini}
url := "https://generativelanguage.googleapis.com/v1beta/models?key=" + key
status, respBody, err := doRequest("GET", url, nil, nil)
if err != nil {
result.Error = err.Error()
return result
}
if status != 200 {
result.Valid = false
var e map[string]interface{}
if json.Unmarshal(respBody, &e) == nil {
if errObj, ok := e["error"].(map[string]interface{}); ok {
result.Error = fmt.Sprintf("%v", errObj["message"])
}
}
return result
}
result.Valid = true
var modelsResp struct {
Models []struct {
Name string `json:"name"`
} `json:"models"`
}
json.Unmarshal(respBody, &modelsResp)
modelSet := map[string]bool{}
for _, m := range modelsResp.Models {
modelSet[m.Name] = true
}
hasModel := func(substr string) bool {
for k := range modelSet {
if strings.Contains(k, substr) {
return true
}
}
return false
}
caps := []struct{ name, key, desc string }{
{"Gemini 2.5 Pro", "gemini-2.5-pro", "Latest flagship Gemini model"},
{"Gemini 2.0 Flash", "gemini-2.0-flash", "Fast multimodal model"},
{"Gemini 1.5 Pro", "gemini-1.5-pro", "Long context (2M tokens)"},
{"Gemini 1.5 Flash", "gemini-1.5-flash", "Lightweight 1.5 variant"},
{"Text Embeddings", "text-embedding", "Embedding generation"},
{"Image generation (Imagen)", "imagen", "Image generation via Imagen"},
}
for _, c := range caps {
result.Capabilities = append(result.Capabilities, Capability{
Name: c.name,
Available: hasModel(c.key),
Description: c.desc,
})
}
return result
}
func validateMistral(key string) ValidationResult {
result := ValidationResult{Provider: ProviderMistral}
status, respBody, err := doRequest("GET", "https://api.mistral.ai/v1/models", map[string]string{
"Authorization": "Bearer " + key,
}, nil)
if err != nil {
result.Error = err.Error()
return result
}
if status != 200 {
result.Valid = false
var e map[string]interface{}
json.Unmarshal(respBody, &e)
if msg, ok := e["message"].(string); ok {
result.Error = msg
}
return result
}
result.Valid = true
var modelsResp struct {
Data []struct {
ID string `json:"id"`
} `json:"data"`
}
json.Unmarshal(respBody, &modelsResp)
modelSet := map[string]bool{}
for _, m := range modelsResp.Data {
modelSet[m.ID] = true
}
caps := []struct{ name, model, desc string }{
{"Mistral Large", "mistral-large-latest", "Flagship model"},
{"Mistral Small", "mistral-small-latest", "Efficient model"},
{"Codestral", "codestral-latest", "Code generation specialist"},
{"Pixtral Large", "pixtral-large-latest", "Vision + text model"},
{"Mistral Embed", "mistral-embed", "Text embeddings"},
}
for _, c := range caps {
result.Capabilities = append(result.Capabilities, Capability{
Name: c.name,
Available: modelSet[c.model],
Description: c.desc,
})
}
return result
}
func validateGroq(key string) ValidationResult {
result := ValidationResult{Provider: ProviderGroq}
status, respBody, err := doRequest("GET", "https://api.groq.com/openai/v1/models", map[string]string{
"Authorization": "Bearer " + key,
}, nil)
if err != nil {
result.Error = err.Error()
return result
}
if status != 200 {
result.Valid = false
return result
}
result.Valid = true
var modelsResp struct {
Data []struct {
ID string `json:"id"`
} `json:"data"`
}
json.Unmarshal(respBody, &modelsResp)
modelSet := map[string]bool{}
for _, m := range modelsResp.Data {
modelSet[m.ID] = true
}
caps := []struct{ name, model, desc string }{
{"Llama 3.3 70B", "llama-3.3-70b-versatile", "Meta's Llama 3.3 70B"},
{"Llama 3.1 8B", "llama-3.1-8b-instant", "Fast 8B model"},
{"DeepSeek R1 Distill (Llama 70B)", "deepseek-r1-distill-llama-70b", "Reasoning distill"},
{"Mixtral 8x7B", "mixtral-8x7b-32768", "Mixtral MoE"},
{"Gemma 2 9B", "gemma2-9b-it", "Google Gemma 2"},
{"Whisper large-v3", "whisper-large-v3", "Speech-to-text"},
}
for _, c := range caps {
result.Capabilities = append(result.Capabilities, Capability{
Name: c.name,
Available: modelSet[c.model],
Description: c.desc,
})
}
return result
}
func validateCohere(key string) ValidationResult {
result := ValidationResult{Provider: ProviderCohere}
payload := map[string]interface{}{
"model": "command-r",
"max_tokens": 1,
"message": "hi",
}
body, _ := json.Marshal(payload)
status, respBody, err := doRequest("POST", "https://api.cohere.com/v1/chat", map[string]string{
"Authorization": "Bearer " + key,
"Content-Type": "application/json",
}, body)
if err != nil {
result.Error = err.Error()
return result
}
if status == 401 || status == 403 {
result.Valid = false
var e map[string]interface{}
json.Unmarshal(respBody, &e)
if msg, ok := e["message"].(string); ok {
result.Error = msg
}
return result
}
result.Valid = true
result.Capabilities = []Capability{
{Name: "Command R+", Available: true, Description: "Flagship RAG-optimized model"},
{Name: "Command R", Available: true, Description: "Efficient instruction-following"},
{Name: "Embed v3", Available: true, Description: "Multilingual embeddings"},
{Name: "Rerank v3", Available: true, Description: "Document reranking"},
}
return result
}
func validateTogether(key string) ValidationResult {
result := ValidationResult{Provider: ProviderTogether}
status, _, err := doRequest("GET", "https://api.together.xyz/v1/models", map[string]string{
"Authorization": "Bearer " + key,
}, nil)
if err != nil {
result.Error = err.Error()
return result
}
result.Valid = status == 200
if !result.Valid {
result.Error = fmt.Sprintf("HTTP %d", status)
return result
}
result.Capabilities = []Capability{
{Name: "Llama 3.1 405B", Available: true, Description: "Meta's largest open model"},
{Name: "Mixtral 8x22B", Available: true, Description: "Large MoE model"},
{Name: "FLUX image gen", Available: true, Description: "Image generation"},
{Name: "Embeddings", Available: true, Description: "Open embedding models"},
{Name: "Fine-tuning", Available: true, Description: "Custom model training"},
}
return result
}
func validatePerplexity(key string) ValidationResult {
result := ValidationResult{Provider: ProviderPerplexity}
payload := map[string]interface{}{
"model": "sonar",
"max_tokens": 1,
"messages": []map[string]string{{"role": "user", "content": "hi"}},
}
body, _ := json.Marshal(payload)
status, _, err := doRequest("POST", "https://api.perplexity.ai/chat/completions", map[string]string{
"Authorization": "Bearer " + key,
"Content-Type": "application/json",
}, body)
if err != nil {
result.Error = err.Error()
return result
}
result.Valid = status == 200 || status == 400 // 400 = auth ok but bad request params
if status == 401 {
result.Valid = false
result.Error = "Invalid API key"
return result
}
result.Valid = true
result.Capabilities = []Capability{
{Name: "Sonar (web search)", Available: true, Description: "Real-time web search + LLM"},
{Name: "Sonar Pro", Available: true, Description: "Advanced search reasoning"},
{Name: "Sonar Deep Research", Available: true, Description: "Multi-step research"},
}
return result
}
func validateDeepSeek(key string) ValidationResult {
result := ValidationResult{Provider: ProviderDeepSeek}
status, respBody, err := doRequest("GET", "https://api.deepseek.com/models", map[string]string{
"Authorization": "Bearer " + key,
}, nil)
if err != nil {
result.Error = err.Error()
return result
}
if status == 401 {
result.Valid = false
var e map[string]interface{}
json.Unmarshal(respBody, &e)
if errObj, ok := e["error"].(map[string]interface{}); ok {
result.Error = fmt.Sprintf("%v", errObj["message"])
}
return result
}
result.Valid = true
result.Capabilities = []Capability{
{Name: "DeepSeek Chat (V3)", Available: true, Description: "Flagship chat model"},
{Name: "DeepSeek Reasoner (R1)", Available: true, Description: "Chain-of-thought reasoning"},
}
return result
}
func validateXAI(key string) ValidationResult {
result := ValidationResult{Provider: ProviderXAI}
status, _, err := doRequest("GET", "https://api.x.ai/v1/models", map[string]string{
"Authorization": "Bearer " + key,
}, nil)
if err != nil {
result.Error = err.Error()
return result
}
result.Valid = status == 200
if !result.Valid {
result.Error = fmt.Sprintf("HTTP %d", status)
return result
}
result.Capabilities = []Capability{
{Name: "Grok 3", Available: true, Description: "xAI flagship model with real-time X data"},
{Name: "Grok 3 mini", Available: true, Description: "Efficient reasoning variant"},
{Name: "Grok Vision", Available: true, Description: "Multimodal image understanding"},
}
return result
}
func validateHuggingFace(key string) ValidationResult {
result := ValidationResult{Provider: ProviderHuggingFace}
status, respBody, err := doRequest("GET", "https://huggingface.co/api/whoami", map[string]string{
"Authorization": "Bearer " + key,
}, nil)
if err != nil {
result.Error = err.Error()
return result
}
if status != 200 {
result.Valid = false
result.Error = fmt.Sprintf("HTTP %d", status)
return result
}
result.Valid = true
var who map[string]interface{}
json.Unmarshal(respBody, &who)
if name, ok := who["name"].(string); ok {
result.RawDetails = map[string]string{"username": name}
}
result.Capabilities = []Capability{
{Name: "Inference API", Available: true, Description: "Hosted model inference"},
{Name: "Model Hub access", Available: true, Description: "Download gated models"},
{Name: "Spaces", Available: true, Description: "Deploy Gradio/Streamlit apps"},
{Name: "Datasets Hub", Available: true, Description: "Access private datasets"},
}
return result
}
func validateReplicate(key string) ValidationResult {
result := ValidationResult{Provider: ProviderReplicate}
status, _, err := doRequest("GET", "https://api.replicate.com/v1/account", map[string]string{
"Authorization": "Bearer " + key,
}, nil)
if err != nil {
result.Error = err.Error()
return result
}
result.Valid = status == 200
if !result.Valid {
result.Error = fmt.Sprintf("HTTP %d", status)
return result
}
result.Capabilities = []Capability{
{Name: "Open source models", Available: true, Description: "Run any model on Replicate"},
{Name: "Custom deployments", Available: true, Description: "Deploy your own models"},
{Name: "Image gen (FLUX, SDXL)", Available: true, Description: "State-of-art image models"},
{Name: "Video generation", Available: true, Description: "Video gen models"},
}
return result
}
func validateUnknown(key string) ValidationResult {
return ValidationResult{
Provider: ProviderUnknown,
Valid: false,
Error: "Could not detect provider from key format. Use --provider flag to specify.",
}
}
// ─── Dispatch ─────────────────────────────────────────────────────────────────
func validate(key string, provider Provider) ValidationResult {
switch provider {
case ProviderAnthropic:
return validateAnthropic(key)
case ProviderOpenAI:
return validateOpenAI(key)
case ProviderGemini:
return validateGemini(key)
case ProviderMistral:
return validateMistral(key)
case ProviderGroq:
return validateGroq(key)
case ProviderCohere:
return validateCohere(key)
case ProviderTogether:
return validateTogether(key)
case ProviderPerplexity:
return validatePerplexity(key)
case ProviderDeepSeek:
return validateDeepSeek(key)
case ProviderXAI:
return validateXAI(key)
case ProviderHuggingFace:
return validateHuggingFace(key)
case ProviderReplicate:
return validateReplicate(key)
default:
return validateUnknown(key)
}
}
// ─── Display ─────────────────────────────────────────────────────────────────
var providerLabels = map[Provider]string{
ProviderAnthropic: "Anthropic",
ProviderOpenAI: "OpenAI",
ProviderGemini: "Google Gemini",
ProviderCohere: "Cohere",
ProviderMistral: "Mistral AI",
ProviderGroq: "Groq",
ProviderTogether: "Together AI",
ProviderPerplexity: "Perplexity AI",
ProviderDeepSeek: "DeepSeek",
ProviderXAI: "xAI (Grok)",
ProviderHuggingFace: "Hugging Face",
ProviderReplicate: "Replicate",
ProviderUnknown: "Unknown",
}
func printResult(r ValidationResult) {
label := providerLabels[r.Provider]
fmt.Printf("%s %s\n", bold("Provider:"), cyan(label))
if r.Valid {
fmt.Printf("%s %s\n", bold("Status: "), green("✓ VALID"))
} else {
fmt.Printf("%s %s\n", bold("Status: "), red("✗ INVALID"))
if r.Error != "" {
fmt.Printf("%s %s\n", bold("Error: "), dim(r.Error))
}
return
}
if r.Model != "" {
fmt.Printf("%s %s\n", bold("Tested: "), dim(r.Model))
}
if len(r.RawDetails) > 0 {
for k, v := range r.RawDetails {
fmt.Printf("%s %s\n", bold(fmt.Sprintf("%-9s", k+":")), dim(v))
}
}
if len(r.Capabilities) > 0 {
fmt.Printf("\n%s\n", bold("Capabilities:"))
for _, c := range r.Capabilities {
icon := green("✓")
if !c.Available {
icon = red("✗")
}
fmt.Printf(" %s %-34s %s\n", icon, c.Name, dim(c.Description))
}
}
}
func printResultJSON(r ValidationResult) {
label := providerLabels[r.Provider]
out := jsonResult{
Provider: label,
Valid: r.Valid,
Error: r.Error,
Model: r.Model,
Details: r.RawDetails,
}
for _, c := range r.Capabilities {
out.Capabilities = append(out.Capabilities, jsonCapability{
Name: c.Name,
Available: c.Available,
Description: c.Description,
})
}
enc := json.NewEncoder(os.Stdout)
enc.SetIndent("", " ")
enc.Encode(out)
}
// ─── Usage ────────────────────────────────────────────────────────────────────
func usage() {
fmt.Printf(`%s — LLM API key validator %s
%s
keyprobe <api-key> [flags]
%s
keyprobe sk-ant-api03-... # auto-detect (Anthropic)
keyprobe sk-proj-... # auto-detect (OpenAI)
keyprobe AIzaSy... # auto-detect (Gemini)
keyprobe --anthropic <key> # force Anthropic
keyprobe --openai <key> # force OpenAI
keyprobe --gemini <key> # force Gemini
keyprobe --mistral <key>
keyprobe --groq <key>
keyprobe --cohere <key>
keyprobe --together <key>
keyprobe --perplexity <key>
keyprobe --deepseek <key>
keyprobe --xai <key>
keyprobe --huggingface <key>
keyprobe --replicate <key>
keyprobe --output json <key> # output as JSON
%s
Validates the key against the provider's live API and reports
which capabilities (models, APIs, features) are accessible.
Detection is automatic when no --provider flag is given.
Use --output json for machine-readable output.
`,
bold("keyprobe"),
dim("v"+version),
bold("Usage:"),
bold("Examples:"),
bold("Notes:"),
)
}
// ─── Main ─────────────────────────────────────────────────────────────────────
func main() {
fs := flag.NewFlagSet("keyprobe", flag.ExitOnError)
fs.Usage = usage
fAnthropic := fs.Bool("anthropic", false, "")
fOpenAI := fs.Bool("openai", false, "")
fGemini := fs.Bool("gemini", false, "")
fMistral := fs.Bool("mistral", false, "")
fGroq := fs.Bool("groq", false, "")
fCohere := fs.Bool("cohere", false, "")
fTogether := fs.Bool("together", false, "")
fPerplexity := fs.Bool("perplexity", false, "")
fDeepSeek := fs.Bool("deepseek", false, "")
fXAI := fs.Bool("xai", false, "")
fHuggingFace := fs.Bool("huggingface", false, "")
fReplicate := fs.Bool("replicate", false, "")
fOutput := fs.String("output", "cli", "")
fVersion := fs.Bool("version", false, "")
// Extract the API key (first non-flag argument) so flags can appear anywhere.
// String flags like --output consume the next token as their value, so we
// must skip those values when hunting for the key.
stringFlags := map[string]bool{"output": true}
var key string
var flagArgs []string
rawArgs := os.Args[1:]
for i := 0; i < len(rawArgs); i++ {
arg := rawArgs[i]
if strings.HasPrefix(arg, "--") {
name := strings.TrimPrefix(arg, "--")
if idx := strings.IndexByte(name, '='); idx >= 0 {
// --flag=value form: entirely self-contained
flagArgs = append(flagArgs, arg)
} else if stringFlags[name] && i+1 < len(rawArgs) {
// --flag value form: consume next token as value
flagArgs = append(flagArgs, arg, rawArgs[i+1])
i++
} else {
flagArgs = append(flagArgs, arg)
}
} else if strings.HasPrefix(arg, "-") && len(arg) == 2 {
flagArgs = append(flagArgs, arg)
} else {
if key == "" {
key = arg
} else {
fmt.Fprintln(os.Stderr, red("error: unexpected argument: "+arg))
os.Exit(1)
}
}
}
fs.Parse(flagArgs)
if *fVersion {
fmt.Println("keyprobe v" + version)
os.Exit(0)
}
if key == "" {
fmt.Fprintln(os.Stderr, red("error: API key is required"))
usage()
os.Exit(1)