Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue using expo/fetch on Android failed with 400 Bad Request #1233

Open
1 task done
younes200 opened this issue Dec 19, 2024 · 1 comment
Open
1 task done

Issue using expo/fetch on Android failed with 400 Bad Request #1233

younes200 opened this issue Dec 19, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@younes200
Copy link

younes200 commented Dec 19, 2024

Confirm this is a Node library issue and not an underlying OpenAI API issue

  • This is an issue with the Node library

Describe the bug

Hi,
When attempting to use expo/fetch on Expo Android, I encountered a 400 Bad Request error. It's unlikely that this issue is related to the trailing slash, as I've already reviewed and ruled out that possibility.

Error: 400 <html>
<head><title>400 Bad Request</title></head>
<body>
<center><h1>400 Bad Request</h1></center>
<hr><center>cloudflare</center>
</body>
</html>
]

To Reproduce

Essentially, using the 'fetch' function directly worked fine. However, when I attempted to use it in conjunction with the OpenAI module, it resulted in failure.

Working :

import { fetch } from 'expo/fetch';
try {
   const response = await fetch('https://api.openai.com/v1/chat/completions', {
     method: 'POST',
     headers: {
       'Content-Type': 'application/json',
       'Authorization': `Bearer sk-XXX`,
     },
     body: JSON.stringify({
       model: "gpt-4o-mini",
       messages: [{ role: "user", content: "Hello, how are you?" }],
    }),
 });
    const data = await response.json();
    console.log(data);
} catch (error) {
    console.error(error);
}

Not working:

import { fetch } from 'expo/fetch';
const openai = new OpenAI({
      apiKey: "XXXX",
}, {
    fetch: fetch
});

try {
   const response = await openai.chat.completions.create({
      model: "gpt-4o-mini",
      messages: [{ role: "user", content: "Hello, how are you?" }],
  });
   console.log(response);
} catch (error) {
  console.error(error);
}

Do you have any insights into why this issue may be occurring?
Thank you

Code snippets

No response

OS

android

Node version

node

Library version

4.77.0

@younes200 younes200 added the bug Something isn't working label Dec 19, 2024
@younes200
Copy link
Author

switching to react-native-fetch-api seems to solve the problem on Expo52

react-native-community/fetch#26 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant