//native
type Assemblyai = {
apiKey: string;
};
/**
* Create temporary authentication token for Streaming STT
* Create a temporary authentication token for Streaming Speech-to-Text
*/
export async function main(auth: Assemblyai, body: { expires_in: number }) {
const url = new URL(`https://api.assemblyai.com/v2/realtime/token`);
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + auth.apiKey,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 33 days ago