Can you send a signedurl from R2 to Whisper model?

I am getting a 500 error in production when trying to send the R2 signed URL. I am not sure what
string
Ai_Cf_Openai_Whisper_Input is expecting?

Error: InferenceUpstreamError: {"httpCode":500,"message":"TypeError: Cannot read properties of undefined (reading 'length')","name":"AiError"}

type Ai_Cf_Openai_Whisper_Input =
  | string
  | {
      audio: number[];
    };


Full code

        await step.do("submitting video to Whisper", async () => {
            // Get the video from R2 and upload it to AssemblyAI
            let uploadUrl: Ai_Cf_Openai_Whisper_Input;
            if (this.env.DEV) {
                // Get the video from R2
                const videoR2 = await this.env.FLIPFEEDS_R2.get(videoR2Key);
                if (!videoR2 || !videoR2.httpMetadata) {
                    console.error("Video not found in storage.");
                    throw new NonRetryableError("Video not found in storage.");
                }

                console.log(
                    `processing ${event.payload.videoId} video with ai...`,
                );
                uploadUrl = {
                    audio: [...new Uint8Array(await videoR2.arrayBuffer())],
                };
            } else {
                const R2_URL = `https://${this.env.CLOUDFLARE_ACCOUNT_ID}.r2.cloudflarestorage.com/flipfeeds-r2`;

                const client = new AwsClient({
                    accessKeyId: this.env.CLOUDFLARE_ACCESS_KEY_ID,
                    secretAccessKey: this.env.CLOUDFLARE_SECRET_ACCESS_KEY,
                });

                const signedUrl = await client.sign(
                    new Request(
                        `${R2_URL}/${videoR2Key}?X-Amz-Expires=${3600}`,
                    ),
                    {
                        aws: { signQuery: true },
                    },
                );

                if (!signedUrl.url.toString()) {
                    console.error("Failed to get signed url.");
                    throw new NonRetryableError("Failed to get signed url.");
                }

                uploadUrl = signedUrl.url.toString();
            }
            // Submit to AI Whisper
            const whisper = await this.env.AI.run(
                "@cf/openai/whisper",
                uploadUrl,
            );

            await this.env.FLIPFEEDS_KV.put(
                whisperKvOriginalKey,
                JSON.stringify(whisper),
            );
        });
Was this page helpful?