Title: Intermittent Unauthorized Errors with DeepInfra Whisper API in Supabase Edge Function Question / Problem: I’m using a Supabase Edge Function (Deno runtime) to transcribe audio via the DeepInfra Whisper API (https://api.deepinfra.com/v1/inference/openai/whisper-large-v3-turbo). The function works fine most of the time, but occasionally it returns an “Unauthorized” (HTTP 401) error. Environment: OS: Any (Supabase Edge runtime) Framework / Platform: Supabase Edge Functions Supabase JS library: @supabase/supabase-js@2 Edge function runtime: Deno Observed Behavior: Requests sent from Postman with the same API key succeed consistently. Requests from the Edge Function intermittently fail with 401 Unauthorized. Supabase Settings: “Verify JWT with legacy secret” is turned off. What I’m trying to achieve: Consistently transcribe audio via the Whisper API from within a Supabase Edge Function and store the transcript in the Supabase database. Steps already taken: Using Deno.env.get("DEEPINFRA_API_KEY") to retrieve the API key. Sending the audio file as FormData in a POST request. Updating the Supabase table after transcription. Edge Function Example: import { serve } from "https://deno.land/std@0.168.0/http/server.ts"; import { createClient } from "https://esm.sh/@supabase/supabase-js@2"; const SUPABASE_URL = "https://your-project.supabase.co"; const SUPABASE_SERVICE_ROLE_KEY = Deno.env.get("SUPABASE_SERVICE_ROLE_KEY")!; const DEEPINFRA_API_KEY = Deno.env.get("DEEPINFRA_API_KEY")!; const supabase = createClient(SUPABASE_URL, SUPABASE_SERVICE_ROLE_KEY); serve(async (req) => { if (req.method === "OPTIONS") { return new Response("ok", { headers: { "Access-Control-Allow-Origin": "*", "Access-Control-Allow-Headers": "authorization, x-client-info, apikey, content-type", "Access-Control-Allow-Methods": "POST, GET, OPTIONS" } }); } try { const { audioUrl, storyId } = await req.json(); if (!audioUrl || !storyId) return new Response(JSON.stringify({ error: "Missing audioUrl or storyId" }), { status: 400 }); const audioResponse = await fetch(audioUrl); if (!audioResponse.ok) throw new Error(`Failed to download audio: ${audioResponse.statusText}`); const audioBuffer = await audioResponse.arrayBuffer(); const audioBlob = new Blob([audioBuffer]); const formData = new FormData(); formData.append("audio", audioBlob); formData.append("chunk_level", "word"); const whisperResponse = await fetch("https://api.deepinfra.com/v1/inference/openai/whisper-large-v3-turbo", { method: "POST", headers: { Authorization: `Bearer ${DEEPINFRA_API_KEY}` }, body: formData }); if (!whisperResponse.ok) { const errorText = await whisperResponse.text(); throw new Error(`Whisper API error: ${whisperResponse.status} - ${errorText}`); } const transcriptionData = await whisperResponse.json(); const wordsJson = JSON.stringify(transcriptionData.words || []); const { data, error } = await supabase.from('audio').update({ transcript: wordsJson }).eq('story_id', storyId).select(); if (error) throw new Error(`Supabase update failed: ${error.message}`); if (!data || data.length === 0) return new Response(JSON.stringify({ error: "No audio record found with the provided story_id" }), { status: 404 }); return new Response(JSON.stringify({ success: true, message: "Audio transcribed and saved successfully", data: { story_id: storyId, transcript: transcriptionData.text, words_count: transcriptionData.words?.length || 0, updated_record: data[0] } }), { status: 200, headers: { "Content-Type": "application/json", "Access-Control-Allow-Origin": "*" } }); } catch (error) { return new Response(JSON.stringify({ error: "Internal server error", message: error.message, timestamp: new Date().toISOString() }), { status: 500, headers: { "Content-Type": "application/json", "Access-Control-Allow-Origin": "*" } }); } }); Questions / Help Needed: Why does the DeepInfra API intermittently return 401 Unauthorized only from the Edge Function? Could this be related to Supabase Edge runtime, cold starts, or request headers? Are there recommended strategies to stabilize authorization for API calls from Edge Functions? If you want, I can also draft a version optimized for maximum clarity, with additional request/response logging and environment details, so the support team can debug faster.