voice-call: thread OpenAI API key through config instead of process.env

RealtimeCallHandler now accepts the pre-resolved key from
config.streaming.openaiApiKey (passed at construction time in runtime.ts),
matching the pattern used by the streaming webhook path. Falls back to
OPENAI_API_KEY env if not set in config, same as streaming.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Forrest Blount 2026-03-11 20:53:12 +00:00
parent 978f06c19a
commit 03d4fa28ca
2 changed files with 5 additions and 2 deletions

View File

@ -179,6 +179,7 @@ export async function createVoiceCallRuntime(params: {
manager,
provider,
coreConfig,
config.streaming.openaiApiKey,
);
webhookServer.setRealtimeHandler(realtimeHandler);
log.info("[voice-call] Realtime voice handler initialized");

View File

@ -36,6 +36,8 @@ export class RealtimeCallHandler {
private manager: CallManager,
private provider: VoiceCallProvider,
private coreConfig: CoreConfig | null,
/** Pre-resolved OpenAI API key (falls back to OPENAI_API_KEY env at call time) */
private openaiApiKey?: string,
) {}
/**
@ -129,9 +131,9 @@ export class RealtimeCallHandler {
callSid: string,
ws: WebSocket,
): OpenAIRealtimeVoiceBridge | null {
const apiKey = process.env.OPENAI_API_KEY;
const apiKey = this.openaiApiKey ?? process.env.OPENAI_API_KEY;
if (!apiKey) {
console.error("[voice-call] No OPENAI_API_KEY for realtime call");
console.error("[voice-call] No OpenAI API key for realtime call (set streaming.openaiApiKey or OPENAI_API_KEY)");
ws.close(1011, "No API key");
return null;
}