From 116b191c9a132663b2641741af553734deec8d44 Mon Sep 17 00:00:00 2001 From: Richard R Date: Tue, 9 Jun 2026 10:32:11 -0600 Subject: [PATCH] fix(tts): allow OpenAI-compatible TTS with empty apiKey by using placeholder Update OpenAI SDK instantiation to provide a placeholder apiKey when none is supplied, enabling support for local or unauthenticated OpenAI-compatible TTS servers. Ensure Authorization header is cleared when not needed. --- src/lib/server/tts/generate.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/lib/server/tts/generate.ts b/src/lib/server/tts/generate.ts index 9599990..dcd8bae 100644 --- a/src/lib/server/tts/generate.ts +++ b/src/lib/server/tts/generate.ts @@ -656,7 +656,12 @@ async function runOpenAiCompatibleRequest( upstreamSettings: ResolvedTtsUpstreamRuntimeSettings, ): Promise { const openai = new OpenAI({ - apiKey: request.apiKey, + // The SDK constructor rejects an empty apiKey, but many OpenAI-compatible + // servers (e.g. a local Supertonic/Kokoro) need no auth. Pass a placeholder to + // satisfy the constructor; `defaultHeaders` clears the Authorization header + // (merged after the bearer auth, and allowed by validateHeaders), so the + // placeholder is never sent. + apiKey: request.apiKey || 'no-key', baseURL: request.baseUrl, defaultHeaders: request.apiKey ? undefined : { Authorization: null }, maxRetries: 0,