Edits history of script submission #11511 for ' Create temporary authentication token for Streaming STT (assemblyai)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //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 423 days ago