File tree Expand file tree Collapse file tree 3 files changed +25
-3
lines changed Expand file tree Collapse file tree 3 files changed +25
-3
lines changed Original file line number Diff line number Diff line change @@ -618,9 +618,17 @@ function debugLog(message: string, data?: any) {
618
618
*/
619
619
function resolveEffectiveBaseUrl ( configManager : ConfigManager ) : string {
620
620
const env = process . env . GROQ_BASE_URL ;
621
- if ( env ) return env . replace ( / \/ + $ / , '' ) + '/openai/v1' ;
621
+ if ( env ) {
622
+ // Don't append /openai/v1 if it's already in the URL
623
+ const normalized = env . replace ( / \/ + $ / , '' ) ;
624
+ return normalized . includes ( '/openai/v1' ) ? normalized : normalized + '/openai/v1' ;
625
+ }
622
626
const cfg = configManager . getBaseUrl ( ) ;
623
- if ( cfg ) return cfg . replace ( / \/ + $ / , '' ) + '/openai/v1' ;
627
+ if ( cfg ) {
628
+ // Don't append /openai/v1 if it's already in the URL
629
+ const normalized = cfg . replace ( / \/ + $ / , '' ) ;
630
+ return normalized . includes ( '/openai/v1' ) ? normalized : normalized + '/openai/v1' ;
631
+ }
624
632
return 'https://api.groq.com/openai/v1' ;
625
633
}
626
634
Original file line number Diff line number Diff line change @@ -38,6 +38,13 @@ async function startChat(
38
38
try {
39
39
// Set base URL if provided via CLI
40
40
if ( baseUrl ) {
41
+ // Validate URL format
42
+ try {
43
+ new URL ( baseUrl ) ;
44
+ } catch ( error ) {
45
+ console . log ( chalk . red ( `Invalid base URL format: ${ baseUrl } ` ) ) ;
46
+ process . exit ( 1 ) ;
47
+ }
41
48
process . env . GROQ_BASE_URL = baseUrl ;
42
49
}
43
50
Original file line number Diff line number Diff line change @@ -144,10 +144,17 @@ export class ConfigManager {
144
144
* This URL will be used when creating the Groq client if GROQ_BASE_URL env var is not set.
145
145
*
146
146
* @param baseUrl - The custom API base URL to save (e.g., "https://custom-api.example.com")
147
- * @throws Error if unable to save the configuration
147
+ * @throws Error if unable to save the configuration or URL is invalid
148
148
*/
149
149
public setBaseUrl ( baseUrl : string ) : void {
150
150
try {
151
+ // Validate URL format
152
+ try {
153
+ new URL ( baseUrl ) ;
154
+ } catch ( error ) {
155
+ throw new Error ( `Invalid URL format: ${ baseUrl } ` ) ;
156
+ }
157
+
151
158
this . ensureConfigDir ( ) ;
152
159
153
160
let config : Config = { } ;
You can’t perform that action at this time.
0 commit comments