Search

3,275 results found for openai (1713ms)

Code
3,180

<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>OpenAI Realtime API Voice Agent</title>
<style>
:root {
# hello-realtime-video
Hello Realtime is a complete OpenAI Realtime application that supports WebRTC
users. You can access the app via WebRTC at
https://hello-realtime-video.val.run.
websocket interface.
If you remix the app, you'll just need to pop in your own OPENAI_API_KEY (from
platform.openai.com).
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>OpenAI Realtime API Voice Agent</title>
<style>
:root {
const MODEL = "gpt-realtime";
const INSTRUCTIONS = `
Greet the user in English, and thank them for trying the new OpenAI Realtime API.
Give them a brief summary based on the list below, and then ask if they have any questions.
Answer questions using the information below. For questions outside this scope,
- higher audio quality
- improved handling of alphanumerics (eg, properly understanding credit card and phone numbers
- support for the OpenAI Prompts API
- support for MCP-based tools
- auto-truncation to reduce context size
const VOICE = "marin";
const OPENAI_API_KEY = Deno.env.get("OPENAI_API_KEY");
if (!OPENAI_API_KEY) {
throw new Error("🔴 OpenAI API key not configured");
}
export function makeHeaders(contentType?: string) {
const obj: Record<string, string> = {
Authorization: `Bearer ${OPENAI_API_KEY}`,
};
if (contentType) obj["Content-Type"] = contentType;
sip.post("/", async (c) => {
// Verify the webhook.
const OPENAI_SIGNING_SECRET = Deno.env.get("OPENAI_SIGNING_SECRET");
if (!OPENAI_SIGNING_SECRET) {
console.error("🔴 webhook secret not configured");
return c.text("Internal error", 500);
}
const webhook = new Webhook(OPENAI_SIGNING_SECRET);
const bodyStr = await c.req.text();
let callId: string | undefined;
// Accept the call.
const url = `https://api.openai.com/v1/realtime/calls/${callId}/accept`;
const headers = makeHeaders("application/json");
const body = JSON.stringify(makeSession());
rtc.post("/", async (c) => {
// Create the call.
const url = "https://api.openai.com/v1/realtime/calls";
const headers = makeHeaders();
const fd = new FormData();
# hello-realtime
Hello Realtime is a complete OpenAI Realtime application that supports both WebRTC and SIP users
You can access the app via WebRTC at https://hello-realtime.val.run, or via SIP by calling 425-8
This demo shows off the new SIP API, the new all-in-one WebRTC API, and the new server-side webs
If you remix the app, you'll just need to pop in your own OPENAI_API_KEY (from platform.openai.c
observer.post("/:callId", async (c) => {
const callId = c.req.param("callId");
const url = `wss://api.openai.com/v1/realtime?call_id=${callId}`;
const ws = new WebSocket(url, { headers: makeHeaders() });
ws.on("open", () => {
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>OpenAI Realtime API Voice Agent</title>
<style>
:root {
## Project Overview
Hello Realtime is an OpenAI Realtime API demo application supporting WebRTC
users. It's built on Val Town's Deno runtime with TypeScript and uses the Hono
framework for routing.
2. **WebRTC Route** (`routes/rtc.ts`)
- Creates OpenAI Realtime calls via POST to `/rtc`
- Handles SDP offer/answer exchange
- Triggers observer WebSocket connection
3. **Observer Route** (`routes/observer.ts`)
- Establishes WebSocket connection to OpenAI
- Monitors call events and transcripts
- Auto-sends `response.create` after connection
4. **Utilities** (`routes/utils.ts`)
- `makeHeaders()`: Adds OpenAI API authentication
- `makeSession()`: Configures Realtime session with model, instructions, and
voice settings
Required:
- `OPENAI_API_KEY`: For all OpenAI API calls
## Val Town Specifics
## Key Implementation Details
- OpenAI Realtime model: `gpt-realtime`
- Voice: `marin` (configurable in utils.ts)
- Audio configuration includes noise reduction for near-field devices