const outspeedApiHost = "api.outspeed.com"; // Or your model provider's URL
const apiKey = "YOUR_OUTSPEED_API_KEY"; // Replace with your actual API key
async function createRealtimeSession(sessionRequestBody) {
const url = `https://${outspeedApiHost}/v1/realtime/sessions`;
console.log(`👉 Creating session using: ${url}`);
try {
const response = await fetch(url, {
method: "POST",
headers: {
"Authorization": `Bearer ${apiKey}`,
"Content-Type": "application/json",
},
body: JSON.stringify(sessionRequestBody),
});
if (!response.ok) {
const errorText = await response.text();
console.error("Session creation failed:", response.status, errorText);
// Handle error appropriately in your application
throw new Error(`Failed to create session: ${errorText}`);
}
const sessionData = await response.json();
console.log("🎉 Session created successfully!", sessionData);
return sessionData; // This contains the ephemeral_key
} catch (error) {
console.error("Error during session creation:", error);
throw error;
}
}