Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/openai-realtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down Expand Up @@ -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, {
});
Expand Down