0

I am trying to make a request to Replicate. When executing the below code on Android, everything works flawlessly.

import 'package:http/http.dart' as http;


    var headers = {
      'Authorization': 'Token $replicate_APIKEY',
      'Content-Type': 'application/json',
    };
    var data =
        '{"version": "30414ee7c4fffc37e260fcab7842b5be470b9b840f2b608f5baa9bbef9a259ed", "input": {"model":"medium","audio": "$downloadUrl"}}';
    var url = Uri.parse('https://api.replicate.com/v1/predictions');

    http.Response res = await http.post(url, headers: headers, body: data);
    print(res.statusCode);

When I try to run it in a web environment, I get an Error: XMLHttpRequest error and in my console I can see

Dev Tools screenshot

with the correct payload and the following headers.

Request URL: https://api.replicate.com/v1/predictions
Referrer Policy: strict-origin-when-cross-origin
Provisional headers are shown
Authorization: Token -REDACTED-
Content-Type: application/json; charset=utf-8
Referer: http://localhost:59140/
sec-ch-ua: "Google Chrome";v="107", "Chromium";v="107", "Not=A?Brand";v="24"
sec-ch-ua-mobile: ?0
sec-ch-ua-platform: "macOS"
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36

The same requests, or to my knowladge an equivalent one works with curl as well:

curl 
--location --request POST 'https://api.replicate.com/v1/predictions' \
--header 'Authorization: Token -REDACTED-' \
--header 'Content-Type: application/json' \
--data-raw '{"version": "30414ee7c4fffc37e260fcab7842b5be470b9b840f2b608f5baa9bbef9a259ed", "input": {"audio": "-REDACTED-"}}'

Please someone educate me on the matter, I have no idea what is going on :)

Peter Toth
  • 678
  • 6
  • 23

0 Answers0