When I create a brand new project using expo (RN version 0.76.5) and run code Fetch() to consume openIA API to generate a text response, it throws a Network Request Failed. When I try to make a call to the openIA API I don’t get any response, just the error Network Request Failed. Here is the fetch I’m sending:
await fetch("https://api.openai.com/v1/chat/completions", {
method: "POST",
headers: {
"Accept": "application/json",
"Content-Type": "application/json",
Authorization: `Bearer ${process.env.EXPO_PUBLIC_API_KEY}`,
},
body: JSON.stringify({
model: "gpt-4o-mini",
prompt: prompt,
temperature: 0.7
})
}).then(response => response.json()).then((data) => {
console.log(data);
}).catch(error => {
console.error('Error making request:', error.message, error.stack);
});
}
In other topics it was recommended to add <uses-permission android:name="android.permission.INTERNET"/>
and android:usesCleartextTraffic="true"
in the AndroidManifest.xml file to solve the problem, however, it is still not working.
João Sertoli is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.