@@ -138,7 +138,7 @@ export const ChatCompletionStream = async (
138138 reasoningEffort : string
139139) => {
140140 const configuration = createOpenAiConfiguration ( apiKey , modelId , dangerouslyAllowBrowser )
141- const openai = createOpenAiClient ( configuration )
141+ const openAiClient = createOpenAiClient ( configuration )
142142
143143 if ( messages . length === 0 ) {
144144 throw new Error ( "No messages in history" )
@@ -148,8 +148,9 @@ export const ChatCompletionStream = async (
148148 const isReasoningModel = isOpenAIReasoningModel ( modelId )
149149
150150 // Ask OpenAI for a streaming chat completion given the prompt
151+ console . debug ( `Using ${ currentHost === OPENAI_API_HOST ? "primary" : "backup" } host: ${ currentHost } ` )
151152 try {
152- const response = await openai . chat . completions
153+ const response = await openAiClient . chat . completions
153154 . create ( {
154155 model : modelId ,
155156 messages : [
@@ -185,11 +186,12 @@ export const ChatCompletionStream = async (
185186 switchToBackupHost ( )
186187
187188 // Retry the request with the backup host,
188- const newConfiguration = createOpenAiConfiguration ( apiKey , modelId , dangerouslyAllowBrowser )
189- const newOpenai = createOpenAiClient ( newConfiguration )
189+ const backupConfiguration = createOpenAiConfiguration ( apiKey , modelId , dangerouslyAllowBrowser )
190+ const backupOpenAiClient = createOpenAiClient ( backupConfiguration )
190191
192+ console . debug ( `Using ${ currentHost === OPENAI_API_HOST ? "primary" : "backup" } host: ${ currentHost } ` )
191193 try {
192- const response = await newOpenai . chat . completions
194+ const response = await backupOpenAiClient . chat . completions
193195 . create ( {
194196 model : modelId ,
195197 messages : [
0 commit comments