MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / validateModel

Function validateModel

source code/utils/model/validateModel.ts:22–84  ·  view source on GitHub ↗
(
  model: string,
)

Source from the content-addressed store, hash-verified

20 * Validates a model by attempting an actual API call.
21 */
22export async function validateModel(
23 model: string,
24): Promise<{ valid: boolean; error?: string }> {
25 const normalizedModel = model.trim()
26
27 // Empty model is invalid
28 if (!normalizedModel) {
29 return { valid: false, error: 'Model name cannot be empty' }
30 }
31
32 // Check against availableModels allowlist before any API call
33 if (!isModelAllowed(normalizedModel)) {
34 return {
35 valid: false,
36 error: `Model '${normalizedModel}' is not in the list of available models`,
37 }
38 }
39
40 // Check if it's a known alias (these are always valid)
41 const lowerModel = normalizedModel.toLowerCase()
42 if ((MODEL_ALIASES as readonly string[]).includes(lowerModel)) {
43 return { valid: true }
44 }
45
46 // Check if it matches ANTHROPIC_CUSTOM_MODEL_OPTION (pre-validated by the user)
47 if (normalizedModel === process.env.ANTHROPIC_CUSTOM_MODEL_OPTION) {
48 return { valid: true }
49 }
50
51 // Check cache first
52 if (validModelCache.has(normalizedModel)) {
53 return { valid: true }
54 }
55
56
57 // Try to make an actual API call with minimal parameters
58 try {
59 await sideQuery({
60 model: normalizedModel,
61 max_tokens: 1,
62 maxRetries: 0,
63 querySource: 'model_validation',
64 messages: [
65 {
66 role: 'user',
67 content: [
68 {
69 type: 'text',
70 text: 'Hi',
71 cache_control: { type: 'ephemeral' },
72 },
73 ],
74 },
75 ],
76 })
77
78 // If we got here, the model is valid
79 validModelCache.set(normalizedModel, true)

Callers 3

callFunction · 0.85
handleModelChangeFunction · 0.85

Calls 5

isModelAllowedFunction · 0.85
sideQueryFunction · 0.85
handleValidationErrorFunction · 0.85
setMethod · 0.80
hasMethod · 0.45

Tested by

no test coverage detected