Created
September 3, 2025 16:57
-
-
Save Aestheticsuraj234/3219b4a9a12298626bf24f54918d6e8a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| "use client"; | |
| import { useState } from "react"; | |
| import { RealtimeSession } from "@openai/realtime"; // install if not already | |
| export default function Home() { | |
| const [session, setSession] = useState<any>(null); | |
| async function handleStartAgent() { | |
| console.log("Requesting temp API key from /api/session..."); | |
| const res = await fetch("/api/session"); | |
| const { tempApiKey } = await res.json(); | |
| console.log("Got temp API key:", tempApiKey); | |
| const newSession = new RealtimeSession({ | |
| apiKey: tempApiKey, | |
| model: "gpt-4o-realtime-preview-2025-06-03", | |
| config: { | |
| inputAudioFormat: "pcm16", | |
| inputAudioNoiseReduction: { type: "near_field" }, | |
| inputAudioTranscription: { | |
| language: "en", | |
| model: "gpt-4o-mini-transcribe", | |
| }, | |
| }, | |
| }); | |
| await newSession.connect(); | |
| console.log("Realtime session connected ✅"); | |
| setSession(newSession); | |
| } | |
| return ( | |
| <main className="p-8"> | |
| <button | |
| onClick={handleStartAgent} | |
| className="bg-blue-600 text-white px-4 py-2 rounded" | |
| > | |
| Start Agent | |
| </button> | |
| </main> | |
| ); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment