Skip to content

Commit c3e37a9

Browse files
Iro96nekomeowww
andauthored
fix: enhance OpenAI provider validation for speech recognition servers (issue #557) (#606)
--------- Co-authored-by: Neko <neko@ayaka.moe>
1 parent b190122 commit c3e37a9

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

packages/stage-ui/src/stores/providers/openai-compatible-builder.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,20 @@ export function buildOpenAICompatibleProvider(
8585
responseChat = await fetch(`${config.baseUrl as string}chat/completions`, { headers: { Authorization: `Bearer ${config.apiKey}`, ...additionalHeaders }, method: 'POST', body: '{"model": "test"}' })
8686
responseModelList = await fetch(`${config.baseUrl as string}models`, { headers: { Authorization: `Bearer ${config.apiKey}`, ...additionalHeaders } })
8787

88-
if (!([200, 400, 401].includes(responseChat.status) || [200, 400, 401].includes(responseModelList.status))) {
89-
errors.push(new Error(`Invalid Base URL, ${config.baseUrl} is not supported`))
88+
// Also try transcription endpoints for speech recognition servers
89+
let responseTranscription = null
90+
try {
91+
// Sending empty FormData is fine; 400 still counts as a valid endpoint
92+
responseTranscription = await fetch(`${config.baseUrl as string}audio/transcriptions`, { headers: { Authorization: `Bearer ${config.apiKey}`, ...additionalHeaders }, method: 'POST', body: new FormData() })
93+
}
94+
catch {
95+
// Transcription endpoint might not exist, that's okay
96+
}
97+
98+
// Accept if any of the endpoints work (chat, models, or transcription)
99+
const validResponses = [responseChat, responseModelList, responseTranscription].filter(r => r && [200, 400, 401].includes(r.status))
100+
if (validResponses.length === 0) {
101+
errors.push(new Error(`Invalid Base URL, ${config.baseUrl} is not supported. Make sure your server supports OpenAI-compatible endpoints.`))
90102
}
91103
}
92104
catch (e) {

0 commit comments

Comments
 (0)