@@ -6,7 +6,7 @@ import OpenAI from 'openai'
66
77interface Config {
88 apiKey : string
9- apiProvider : 'openai' | 'gemini' | 'groq'
9+ apiProvider : 'openai' | 'gemini' | 'groq' | 'cerebras'
1010 extractionModel : string
1111 solutionModel : string
1212 debuggingModel : string
@@ -62,7 +62,10 @@ export class ConfigManager extends EventEmitter {
6262 }
6363 }
6464
65- private sanitizeModelSelection ( model : string , provider : 'openai' | 'gemini' | 'groq' ) {
65+ private sanitizeModelSelection (
66+ model : string ,
67+ provider : 'openai' | 'gemini' | 'groq' | 'cerebras'
68+ ) {
6669 if ( provider === 'openai' ) {
6770 const allowedModels = [ 'gpt-4o-mini' , 'gpt-4o' ]
6871 if ( ! allowedModels . includes ( model ) ) {
@@ -101,6 +104,24 @@ export class ConfigManager extends EventEmitter {
101104 return 'meta-llama/llama-4-scout-17b-16e-instruct'
102105 }
103106 return model
107+ } else if ( provider === 'cerebras' ) {
108+ const allowedModels = [
109+ 'llama-4-scout-17b-16e-instruct' ,
110+ 'llama3.1-8b' ,
111+ 'llama-3.3-70b' ,
112+ 'qwen-3-32b' ,
113+ 'llama-4-maverick-17b-128e-instruct' ,
114+ 'qwen-3-235b-a22b-instruct-2507' ,
115+ 'qwen-3-235b-a22b-thinking-2507' ,
116+ 'qwen-3-coder-480b'
117+ ]
118+ if ( ! allowedModels . includes ( model ) ) {
119+ console . log (
120+ `Invalid model: ${ model } for provider: ${ provider } . Defaulting to llama-4-scout-17b-16e-instruct`
121+ )
122+ return 'llama-4-scout-17b-16e-instruct'
123+ }
124+ return model
104125 }
105126 return model
106127 }
@@ -240,20 +261,25 @@ export class ConfigManager extends EventEmitter {
240261 return ! ! config . apiKey && config . apiKey . trim ( ) . length > 0
241262 }
242263
243- public isValidApiKeyFormat ( apiKey : string , provider ?: 'openai' | 'gemini' | 'groq' ) : boolean {
264+ public isValidApiKeyFormat (
265+ apiKey : string ,
266+ provider ?: 'openai' | 'gemini' | 'groq' | 'cerebras'
267+ ) : boolean {
244268 if ( provider === 'openai' ) {
245269 return apiKey . trim ( ) . startsWith ( 'sk-' )
246270 } else if ( provider === 'gemini' ) {
247271 return apiKey . trim ( ) . startsWith ( 'AIzaSyB' )
248272 } else if ( provider === 'groq' ) {
249273 return apiKey . trim ( ) . startsWith ( 'gsk_' )
274+ } else if ( provider === 'cerebras' ) {
275+ return apiKey . trim ( ) . startsWith ( 'csk-' )
250276 }
251277 return false
252278 }
253279
254280 public async testApiKey (
255281 apiKey : string ,
256- provider ?: 'openai' | 'gemini' | 'groq'
282+ provider ?: 'openai' | 'gemini' | 'groq' | 'cerebras'
257283 ) : Promise < {
258284 valid : boolean
259285 error ?: string
@@ -263,6 +289,8 @@ export class ConfigManager extends EventEmitter {
263289 provider = 'openai'
264290 } else if ( apiKey . trim ( ) . startsWith ( 'gsk_' ) ) {
265291 provider = 'groq'
292+ } else if ( apiKey . trim ( ) . startsWith ( 'csk-' ) ) {
293+ provider = 'cerebras'
266294 } else {
267295 provider = 'gemini'
268296 }
@@ -274,6 +302,8 @@ export class ConfigManager extends EventEmitter {
274302 return this . testGeminiKey ( )
275303 } else if ( provider === 'groq' ) {
276304 return this . testGroqKey ( apiKey )
305+ } else if ( provider === 'cerebras' ) {
306+ return this . testCerebrasKey ( apiKey )
277307 }
278308
279309 return { valid : false , error : 'Invalid provider' }
@@ -339,6 +369,37 @@ export class ConfigManager extends EventEmitter {
339369 }
340370 }
341371
372+ private async testCerebrasKey ( apiKey : string ) : Promise < {
373+ valid : boolean
374+ error ?: string
375+ } > {
376+ try {
377+ const response = await fetch ( 'https://api.cerebras.ai/v1/models' , {
378+ headers : {
379+ Authorization : `Bearer ${ apiKey } ` ,
380+ 'Content-Type' : 'application/json'
381+ }
382+ } )
383+
384+ if ( ! response . ok ) {
385+ throw new Error ( `API request failed with status ${ response . status } ` )
386+ }
387+
388+ const data = await response . json ( )
389+ if ( data && Array . isArray ( data . data ) ) {
390+ return { valid : true }
391+ }
392+
393+ return { valid : false , error : 'Invalid API response' }
394+ } catch ( error ) {
395+ console . error ( 'Cerebras API key test failed:' , error )
396+ return {
397+ valid : false ,
398+ error : error instanceof Error ? error . message : 'Failed to validate Cerebras API key'
399+ }
400+ }
401+ }
402+
342403 public getOpacity ( ) : number {
343404 const config = this . loadConfig ( )
344405 return config . opacity !== undefined ? config . opacity : 1.0
0 commit comments