ERROR 401 Missing bearer or basic authentication in header GPT ASSISTANT

I tried and also I reinstall the dependecies, but I´m still having the same issue, Error: 401 Missing bearer or basic authentication in header. I t seems that library is broken for React Native or still in developmemt

Did you make any progress on this?

I’m experiencing this when attempting to use the assistants API in my React Native app running in Expo Go. I’ve verified that the API works for me with the given model, API key, etc. when running locally in a vanilla Node.js project - so I’m guessing it’s something with React or Expo. I’m hardcoding my API key for testing so it’s definitely not the lack of the environment variable.

1 Like

I was also facing that issue, but when trying to create a thread.
Error was the same “ERROR 401 Missing bearer …”.

In the end it turned out that I didn’t attach empty string as a request body (which was present in API reference). I don’t think this is 401 , but I recommend to review not only a token/authorization part but generally entire request (if it exactly matches API reference).

@filiptrn40 @awolnikowski

hey how did you fix this? I am getting same issue for react native? I am trying to retrieve an assistant with this code but getting “401 Missing bearer or basic authentication in header”?

const openAiInitiate = new OpenAI({
apiKey: “myapikey”,
});

const assistant = await openAiInitiate.beta.assistants.retrieve(
“myassistantid”
);

I wasn’t able to get the API to work directly in my React app, even though it seems like dangerouslyAllowBrowser should allow that. I ended up setting up a simple back end with AWS Lambdas that invoke the OpenAI API and pass on the results to my app.

@filiptrn40 not sure if either of you are still working on this, but I have found the only way to get openai stuff to work in react native is to essentially follow the curl instructions. For example:

 const runResponse = await fetch(`https://api.openai.com/v1/threads/${threadId}/runs`, {
                method: "POST",
                headers: {
                    "Content-Type": "application/json",
                    'Authorization': `Bearer APIKEY`, //hardcoded
                    'OpenAI-Beta': 'assistants=v1',
                },
                body: JSON.stringify({
                    assistant_id: "assistant id",

All of my interactions and calls follow the curl instructions and generally that seems to work.

Hello, I see that you have made progress on a very important point regarding my thesis. Could you please include the parts of your code related to the assistant API? I am working on the assistant API with React Native and I would like to ask a lot from you😊

What questions do you have? I’m happy to help as best I can.

Hello, I am building a chatbot in React Native. I want to direct the questions in the chatbot to my assistant that I created in the openaa interface, but I do not know how to send a request to the assistant. Could you please share with me the codes related to the request you sent to the assistant?

So the only key thing that I’ve come across when doing anything OpenAI on react native is to use the curl instructions. You would think you could use the node sdk, but I’ve found and some googling will show that the way to make OpenAI api’s work is just do follow the adjusted curl instructions. If you read the documentation knowing that you need to use the curl instructions it’s pretty straightforward. This is a piece of the create message for the assistant api. If you read the documentation follow the curl instructions and look at this example you should be all set.

fetch(`https://api.openai.com/v1/threads/${threadId}/messages`, {
                    method: "POST",
                    headers: {
                        "Content-Type": "application/json",
                        'Authorization': `Bearer  YOUR_API_KEY`,
                        'OpenAI-Beta': 'assistants=v1',
                    },
                    body: JSON.stringify({
                        role: "user",
                        inputs: {
                            text: userMessage.text,  // Pass along any user-entered text
                        },
                    })
                });