MCPcopy Create free account
hub / github.com/HELPMEEADICE/doge-code / validateModel

Function validateModel

src/utils/model/validateModel.ts:22–93  ·  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 const customBaseURL = readCurrentCustomApiProvider()?.baseURL
27
28 // Empty model is invalid
29 if (!normalizedModel) {
30 return { valid: false, error: 'Model name cannot be empty' }
31 }
32
33 // Check against availableModels allowlist before any API call
34 if (!isModelAllowed(normalizedModel)) {
35 return {
36 valid: false,
37 error: `Model '${normalizedModel}' is not in the list of available models`,
38 }
39 }
40
41 // Check if it's a known alias (these are always valid)
42 const lowerModel = stripModelContextSuffix(normalizedModel).toLowerCase()
43 if ((MODEL_ALIASES as readonly string[]).includes(lowerModel)) {
44 return { valid: true }
45 }
46
47 // Check if it matches ANTHROPIC_CUSTOM_MODEL_OPTION (pre-validated by the user)
48 if (normalizedModel === process.env.ANTHROPIC_CUSTOM_MODEL_OPTION) {
49 return { valid: true }
50 }
51
52 // For custom Anthropic-compatible gateways, allow arbitrary model strings.
53 // Many OpenAI-compatible/relay providers expose non-Claude identifiers such as
54 // gpt-5.4 while still speaking the Anthropic wire format.
55 if (customBaseURL && customBaseURL.trim() !== '') {
56 validModelCache.set(normalizedModel, true)
57 return { valid: true }
58 }
59
60 // Check cache first
61 if (validModelCache.has(normalizedModel)) {
62 return { valid: true }
63 }
64
65
66 // Try to make an actual API call with minimal parameters
67 try {
68 await sideQuery({
69 model: normalizedModel,
70 max_tokens: 1,
71 maxRetries: 0,
72 querySource: 'model_validation',
73 messages: [
74 {
75 role: 'user',
76 content: [
77 {
78 type: 'text',
79 text: 'Hi',

Callers 3

callFunction · 0.85
handleModelChangeFunction · 0.85

Calls 7

isModelAllowedFunction · 0.85
stripModelContextSuffixFunction · 0.85
sideQueryFunction · 0.85
handleValidationErrorFunction · 0.85
setMethod · 0.65
hasMethod · 0.45

Tested by

no test coverage detected