Error 401 Open AI API Failure

I’m trying to get my Open AI API key (tested on Postman, it works) to work in Adalo as a custom action tied to a button. I’ve updated my API across my adalo account and double checked it in this action.

I have rewritten/double checked my code many times and still get this error no matter what. Has anyone else had this?

"An error occurred when performing your API request
Request failed with status code 401

Full Response:

{
“error”: {
“message”: “You didn’t provide an API key. You need to provide your API key in an Authorization header using Bearer auth (i.e. Authorization: Bearer YOUR_KEY), or as the password field (with blank username) if you’re accessing the API from your browser and are prompted for a username and password. You can obtain an API key from https://platform.openai.com/account/api-keys.”,
“type”: “invalid_request_error”,
“param”: null,
“code”: null
}
}

My code is as follows:

API Base URL
https://api.openai.com/v1/completions

Method
POST

Headers
Content-Type: application/json
Authorization: Bearer MY_API_KEY

Body
{
“model”: “gpt-3.5-turbo-instruct”,
“prompt”: “MY_PROMPT”,
“max_tokens”: 500
}

Welcome to the community @devonkelley :partying_face:

For the authorization header value, you need to enter Bearer<space>api_key

Now once you enter the Bearer word on the header value, don’t add the space and enter the api key. After entering that, add the space between Bearer and api_key you entered.

Ah shoot, that unfortunately did not fix it to add the space afterwards. But thank you!!

You copied the api key and pasted on the header value right? So it’s Bearer<space>api_key.

Yes, I copied and pasted the key. the header value is Bearerapi_key, with api_key being replaced by my actual key of course :slight_smile:

I’ve tested the key itself in postman and the key works.

Hey, I had this problem before too! Make sure there are no extra spaces or characters when copying the API key. Also, check if the format is correct. If it’s still not working, try creating a new key in OpenAI and update it in Adalo.