Skip to content
Open
Show file tree
Hide file tree
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
43 changes: 22 additions & 21 deletions webapp/app/api/session/route.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
import { NextResponse } from "next/server";

export async function GET() {
try {
const r = await fetch("https://api.openai.com/v1/realtime/sessions", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.OPENAI_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
model: "gpt-4o-realtime-preview-2025-06-03",
voice: "verse",
}),
});

if (!r.ok) {
const error = await r.text();
return Response.json({ error }, { status: 500 });
}

const data = await r.json();
return Response.json(data);
const response = await fetch(
"https://api.openai.com/v1/realtime/sessions",
{
method: "POST",
headers: {
Authorization: `Bearer ${process.env.OPENAI_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
model: "gpt-4o-realtime-preview-2025-06-03",
}),
}
);
const data = await response.json();
return NextResponse.json(data);
} catch (error) {
console.error("Error creating realtime session:", error);
return Response.json({ error: "Internal server error" }, { status: 500 });
console.error("Error in /session:", error);
return NextResponse.json(
{ error: "Internal Server Error" },
{ status: 500 }
);
}
}
10 changes: 9 additions & 1 deletion webapp/components/voice-mini-app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,16 @@ const VoiceMiniApp = () => {
await connect({
getEphemeralKey: async () => {
const res = await fetch("/api/session");
if (!res.ok) {
const error = await res.text();
throw new Error(error || "Failed to fetch session");
}
const data = await res.json();
return data?.client_secret?.value;
const ek = data?.client_secret?.value;
if (!ek) {
throw new Error("No ephemeral key returned");
}
return ek;
},
initialAgents: [agent],
audioElement: audioRef.current ?? undefined,
Expand Down