diff --git a/src/openai-realtime.ts b/src/openai-realtime.ts index 464cc08..9a13288 100644 --- a/src/openai-realtime.ts +++ b/src/openai-realtime.ts @@ -61,22 +61,22 @@ export class OpenAIRealtimeAdapter implements MultimodalAdapter { ? `${this.config.apiKey.slice(0, 7)}...${this.config.apiKey.slice(-4)} (${this.config.apiKey.length} chars)` : "(empty)"; console.log(dim(`[voice] API key: ${keyPreview}`)); - const sessionResp = await fetch("https://api.openai.com/v1/realtime/sessions", { + const sessionResp = await fetch("https://api.openai.com/v1/realtime/client_secrets", { method: "POST", headers: { "Authorization": `Bearer ${this.config.apiKey}`, "Content-Type": "application/json", }, - body: JSON.stringify({ model }), + body: JSON.stringify({ session: { type: "realtime", model } }), }); if (!sessionResp.ok) { const body = await sessionResp.text(); throw new Error(`Failed to create realtime session: ${sessionResp.status} ${body}`); } - const session = await sessionResp.json() as { client_secret?: { value?: string } }; - const ephemeralKey = session.client_secret?.value; + const session = await sessionResp.json() as { value?: string }; + const ephemeralKey = session.value; if (!ephemeralKey) { - throw new Error("No ephemeral key returned from realtime sessions endpoint"); + throw new Error("No ephemeral key returned from realtime client_secrets endpoint"); } await this.connectWs(url, { @@ -298,14 +298,14 @@ export class OpenAIRealtimeAdapter implements MultimodalAdapter { const msg = err?.message || ""; if (!msg.includes("authentication") && !msg.includes("401")) throw err; // Ephemeral token fallback (matches connect() path) - const sessionResp = await fetch("https://api.openai.com/v1/realtime/sessions", { + const sessionResp = await fetch("https://api.openai.com/v1/realtime/client_secrets", { method: "POST", headers: { Authorization: `Bearer ${this.config.apiKey}`, "Content-Type": "application/json" }, - body: JSON.stringify({ model }), + body: JSON.stringify({ session: { type: "realtime", model } }), }); if (!sessionResp.ok) throw new Error(`refresh ephemeral token: ${sessionResp.status}`); - const session = (await sessionResp.json()) as { client_secret?: { value?: string } }; - const ephemeralKey = session.client_secret?.value; + const session = (await sessionResp.json()) as { value?: string }; + const ephemeralKey = session.value; if (!ephemeralKey) throw new Error("No ephemeral key on refresh"); await this.connectWs(url, { });