@@ -912,19 +912,6 @@ export class ProviderConfigManager {
912912 ) ,
913913 ) ;
914914
915- const apiKey =
916- ( await showPassword ( {
917- title : t ( "providers.config.enterApiKey" , {
918- provider : t ( "providers.openaicompatible" ) ,
919- } ) ,
920- placeholder : t ( "ui.apiKeyPlaceholder" ) ,
921- } ) ) ?? "" ;
922-
923- if ( ! apiKey ) {
924- console . log ( chalk . gray ( "\n" + t ( "providers.config.cancelled" ) ) ) ;
925- return ;
926- }
927-
928915 const baseUrlInput = await showInput ( {
929916 title : t ( "providers.config.changeBaseUrl" ) ,
930917 defaultValue :
@@ -938,6 +925,26 @@ export class ProviderConfigManager {
938925 return ;
939926 }
940927
928+ const apiKeyInput = await showPassword ( {
929+ title : t ( "providers.config.enterApiKeyOptional" , {
930+ provider : t ( "providers.openaicompatible" ) ,
931+ } ) ,
932+ placeholder : t ( "ui.apiKeyPlaceholder" ) ,
933+ validate : ( val : string ) => {
934+ const trimmed = val ?. trim ( ) ;
935+ if ( ! trimmed ) return true ;
936+ if ( trimmed . length < 10 ) return t ( "providers.config.apiKeyTooShort" ) ;
937+ return true ;
938+ } ,
939+ } ) ;
940+
941+ if ( apiKeyInput === undefined || apiKeyInput === null ) {
942+ console . log ( chalk . gray ( "\n" + t ( "providers.config.cancelled" ) ) ) ;
943+ return ;
944+ }
945+
946+ const apiKey = apiKeyInput . trim ( ) ;
947+
941948 const model = await showInput ( {
942949 title : t ( "providers.config.enterModelId" ) ,
943950 defaultValue :
@@ -955,10 +962,10 @@ export class ProviderConfigManager {
955962 sanitizedModel ,
956963 ) ;
957964 this . runtime . config . openaicompatible = {
958- apiKey,
959965 baseUrl,
960966 model : sanitizedModel ,
961967 contextWindow,
968+ ...( apiKey ? { apiKey } : { } ) ,
962969 } ;
963970
964971 this . runtime . config . provider = "openaicompatible" ;
@@ -2361,19 +2368,26 @@ export class ProviderConfigManager {
23612368 title : t ( "providers.config.enterApiKey" , { provider : providerName } ) ,
23622369 placeholder : t ( "ui.apiKeyPlaceholder" ) ,
23632370 validate : ( val : string ) => {
2364- if ( ! val ?. trim ( ) ) return t ( "providers.config.apiKeyRequired" ) ;
2365- if ( val . length < 10 ) return t ( "providers.config.apiKeyTooShort" ) ;
2371+ const trimmed = val ?. trim ( ) ;
2372+ if ( ! trimmed ) {
2373+ return provider === "openaicompatible"
2374+ ? true
2375+ : t ( "providers.config.apiKeyRequired" ) ;
2376+ }
2377+ if ( trimmed . length < 10 ) return t ( "providers.config.apiKeyTooShort" ) ;
23662378 return true ;
23672379 } ,
23682380 } ) ;
23692381
2370- if ( ! apiKey ) {
2382+ if ( apiKey === undefined || apiKey === null ) {
23712383 console . log (
23722384 chalk . gray ( "\n" + t ( "providers.config.settingsChangeCancelled" ) ) ,
23732385 ) ;
23742386 return ;
23752387 }
23762388
2389+ const trimmedApiKey = apiKey . trim ( ) ;
2390+
23772391 if ( provider === "openaicompatible" ) {
23782392 const baseUrlInput = await showInput ( {
23792393 title : t ( "providers.config.changeBaseUrl" ) ,
@@ -2403,26 +2417,32 @@ export class ProviderConfigManager {
24032417 newBaseUrl = baseUrlInput . trim ( ) . replace ( / \/ + $ / , "" ) ;
24042418 }
24052419
2406- // Validate the API key
2407- console . log ( chalk . gray ( "\n" + t ( "providers.config.validatingApiKey" ) ) ) ;
2408- const validationResult = await this . validateApiKey (
2409- provider ,
2410- apiKey . trim ( ) ,
2411- provider === "openaicompatible"
2412- ? newBaseUrl
2413- : provider === "openai"
2414- ? ( this . runtime . config . openai ?. baseUrl ?? currentSettings ?. baseUrl )
2415- : undefined ,
2416- ) ;
2420+ if ( provider === "openaicompatible" && ! trimmedApiKey ) {
2421+ newApiKey = "" ;
2422+ } else {
2423+ // Validate the API key
2424+ console . log ( chalk . gray ( "\n" + t ( "providers.config.validatingApiKey" ) ) ) ;
2425+ const validationResult = await this . validateApiKey (
2426+ provider ,
2427+ trimmedApiKey ,
2428+ provider === "openaicompatible"
2429+ ? newBaseUrl
2430+ : provider === "openai"
2431+ ? ( this . runtime . config . openai ?. baseUrl ?? currentSettings ?. baseUrl )
2432+ : undefined ,
2433+ ) ;
24172434
2418- if ( ! validationResult . valid ) {
2419- console . log ( chalk . red ( `\n✗ ${ validationResult . error } ` ) ) ;
2420- console . log ( chalk . gray ( validationResult . hint || "" ) ) ;
2421- return ;
2422- }
2435+ if ( ! validationResult . valid ) {
2436+ console . log ( chalk . red ( `\n✗ ${ validationResult . error } ` ) ) ;
2437+ console . log ( chalk . gray ( validationResult . hint || "" ) ) ;
2438+ return ;
2439+ }
24232440
2424- console . log ( chalk . green ( "✓ " + t ( "providers.config.apiKeyValid" ) + "\n" ) ) ;
2425- newApiKey = apiKey . trim ( ) ;
2441+ console . log (
2442+ chalk . green ( "✓ " + t ( "providers.config.apiKeyValid" ) + "\n" ) ,
2443+ ) ;
2444+ newApiKey = trimmedApiKey ;
2445+ }
24262446 }
24272447
24282448 // Handle model change
@@ -2665,10 +2685,10 @@ export class ProviderConfigManager {
26652685 } ;
26662686 } else if ( provider === "openaicompatible" ) {
26672687 this . runtime . config . openaicompatible = {
2668- apiKey : newApiKey ,
26692688 baseUrl,
26702689 model : newModel ,
26712690 contextWindow,
2691+ ...( newApiKey ? { apiKey : newApiKey } : { } ) ,
26722692 } ;
26732693 } else if ( provider === "openrouter" ) {
26742694 this . runtime . config . openrouter = {
0 commit comments