@@ -154,13 +154,19 @@ When asked about your identity, you should identify yourself as a coding assista
154
154
debugLog ( 'API key provided:' , apiKey ? `${ apiKey . substring ( 0 , 8 ) } ...` : 'empty' ) ;
155
155
this . apiKey = apiKey ;
156
156
157
- // Check for base URL in config file (SDK handles GROQ_BASE_URL env var automatically)
157
+ // Base URL precedence: 1) ENV (handled by SDK), 2) config fallback
158
+ const envBaseURL = process . env . GROQ_BASE_URL ?. trim ( ) ;
158
159
const configBaseURL = this . configManager . getBaseUrl ( ) ;
159
- if ( configBaseURL ) {
160
- debugLog ( `Using base URL from config: ${ configBaseURL } ` ) ;
161
- this . client = new Groq ( { apiKey, baseURL : configBaseURL } ) ;
160
+ if ( envBaseURL ) {
161
+ debugLog ( `Using base URL from environment: ${ envBaseURL } ` ) ;
162
+ // Let SDK pick up GROQ_BASE_URL automatically
163
+ this . client = new Groq ( { apiKey } ) ;
164
+ } else if ( configBaseURL ) {
165
+ const normalized = configBaseURL . replace ( / \/ + $ / , '' ) ;
166
+ debugLog ( `Using base URL from config: ${ normalized } ` ) ;
167
+ this . client = new Groq ( { apiKey, baseURL : normalized } ) ;
162
168
} else {
163
- // SDK will automatically use GROQ_BASE_URL env var if set
169
+ // Default SDK behavior
164
170
this . client = new Groq ( { apiKey } ) ;
165
171
}
166
172
@@ -621,14 +627,20 @@ function resolveEffectiveBaseUrl(configManager: ConfigManager): string {
621
627
function generateCurlCommand ( apiKey : string , requestBody : any , requestCount : number , baseUrl : string ) : string {
622
628
if ( ! debugEnabled ) return '' ;
623
629
624
- const maskedApiKey = `${ apiKey . substring ( 0 , 8 ) } ...${ apiKey . substring ( apiKey . length - 8 ) } ` ;
630
+ const maskApiKey = ( key : string ) => {
631
+ if ( key . length <= 6 ) return '***' ;
632
+ if ( key . length <= 12 ) return `${ key . slice ( 0 , 3 ) } ***${ key . slice ( - 2 ) } ` ;
633
+ return `${ key . slice ( 0 , 6 ) } ...${ key . slice ( - 4 ) } ` ;
634
+ } ;
635
+ const maskedApiKey = maskApiKey ( apiKey ) ;
625
636
626
637
// Write request body to JSON file
627
638
const jsonFileName = `debug-request-${ requestCount } .json` ;
628
639
const jsonFilePath = path . join ( process . cwd ( ) , jsonFileName ) ;
629
640
fs . writeFileSync ( jsonFilePath , JSON . stringify ( requestBody , null , 2 ) ) ;
630
641
631
- const curlCmd = `curl -X POST "${ baseUrl } /chat/completions" \\
642
+ const endpoint = `${ baseUrl . replace ( / \/ + $ / , '' ) } /chat/completions` ;
643
+ const curlCmd = `curl -X POST "${ endpoint } " \\
632
644
-H "Authorization: Bearer ${ maskedApiKey } " \\
633
645
-H "Content-Type: application/json" \\
634
646
-d @${ jsonFileName } ` ;
0 commit comments