deepgram / deepgram-js-sdk

Official JavaScript SDK for Deepgram's automated speech recognition APIs.
https://developers.deepgram.com
MIT License
127 stars 45 forks source link

Calling rest api from supabase edge function trigger CORS error #291

Open wliumelb opened 1 month ago

wliumelb commented 1 month ago

What is the current behavior?

Calling transcribeUrl api from deployed supabase edge function return CORS error:

Due to CORS we are unable to support REST-based API calls to our API from the browser. Please consider using a proxy, and including a restProxy: { url: ''} in your Deepgram client options.

Steps to reproduce

run this function from deployed supabase edge function

import { createClient } from "https://esm.sh/@deepgram/sdk@3.3.2";
import { deepgramApiKey } from "../_shared/deepgram_key.ts";

export const transcribeRecording = async (input: {
  url: string
}) => {
  const { url } = input;

  const deepgram = createClient(deepgramApiKey);

  const { result, error } = await deepgram.listen.prerecorded.transcribeUrl(
    {
      url,
    },
    {
      model: "nova-2",
      detect_language: true,
      paragraphs: true,
    }
  );
};

Expected behavior

CORS error should not be triggered as it is not in a browser

Please tell us about your environment

Supabase edge runtime

Other information

The bug is caused by this line of code: https://github.com/deepgram/deepgram-js-sdk/blob/875650806ba46fc48adc817d44df48227771b2eb/src/lib/helpers.ts#L17

In the supabase edge run time, the 'window' global variable is an object rather than undefined

lukeocodes commented 1 month ago

Nice, it's hard for us to test all these different edge runtimes. I'll think about a better way to determine whether we require a proxy or not

rallu commented 3 weeks ago

Same problem with using Deno Deploy. I suggest reducing the number of checks for "stupid user" errors.