POST request with API key vs. "Make an API Key Auth request". Is there a difference?

Dear everyone,

I just spent two hours getting a “Make an API Key Auth request” HTTP module to work with no success. I added every possible combination of “My API auth key” to the keychain. But every time I ran the module, I got an “Missing Authentication header” error.

In the end I switched to a simple "Make a request HTTP module and added the API key as header items manually (not via the keychain) and that finally worked.

So I’m wondering: is there a difference between using these two modules that I’m not aware of? Or did I make some other mistake? Any feedback would be much appreciated!

And yes, I deleted the API key in the screenshots, it’s no longer working :slight_smile:

Here’s what I did with screenshots:
So I at first I tried adding my API key to the keychain. I used every value I could think of for API Key parameter name: “Authentication”, “Bearer”, “X-API-Key”, “X-API-KEY”, the name for the API key as I chose it in the service I tried to connect to. Nothing worked.

It always came back with “error: missing authentication header” in the output section and the Header empty in the Input section.

Then I switched to a plain HTTP module without API keychain.
I entered the headers manually. And that worked like a charm.

And here’s a curl statement form the API docs of the service I tried connecting to
curl https://openrouter.ai/api/v1/chat/completions
-H “Content-Type: application/json”
-H “Authorization: Bearer $OPENROUTER_API_KEY”
-d ‘{
“model”: “openai/gpt-3.5-turbo”,
“messages”: [
{“role”: “user”, “content”: “What is the meaning of life?”}
]
}’

Thank you!

Hi @weiphi,

I think the issue is that the header isn’t called “X-API-Key” as it’s in your setup but OpenAi expects “Authorization” Header. Both headers are common ways to authenticate and some APIs even do have some weird custom headers :smiley:

The difference is with the plain HTTP module, everyone who opens the module sees the API Key whereas using the API Key Module it’s safer.

2 Likes

Thanks for your fast reply!

I tried calling the header “Authorization” in the Make API Key Auth module too, when I saved the key in the keychain, but that didn’t work either.

And yes, storing the API key in the keychain is safer than “storing” the API key in a module. That’s why I tried to do it that way first :slight_smile:

Did you also use "Bearer " so speaking Bearer plus space plus your token?
Because what happens is the following: Make somewhere stores this particular information and uses it to do the API Call. They don’t know if Bearer should be there or not - same goes here. Some APIs use “Bearer”, some don’t, some put custom words in front :smiley:

2 Likes

Yes thanks, I used “Bearer”, I used “X-API-Key” and “X-API-KEY”. I called “Pretty Please Just Work Already” :slight_smile: As I said, i tried for two hours to get this module working.

Mhm, so if I used the API Key Module and use input everything, it looks great.
The “Headers” array is empty because they don’t want to show the API Key but it’s present in the API call and the result is good :slight_smile:


2 Likes

Maybe a wrong API key?
Or maybe they want the API key to be base64 encoded?

The docs are very vague so maybe give it a try.

2 Likes

Thanks! No it wasn’t a wrong key. I copy and pasted the same key into both modules and it didn’t work in the API Key Auth module but it did work in the simple HTTP module.

How can I specify in a API Key Auth module that a key has to be base64 encoded?

Welcome to the Make community!

What @Richard_Johannes said was correct, and I am able to create a keychain as follows:

Keychain setup

Note: the Bearer <token> goes into the Key field, and the Authorization goes into the parameter name field. Make sure the spelling is correct and that there are no leading or trailing spaces.

Sample request

Here is a sample request I made:

Output

Status code 200 means the request was successful

Your problem

I think your issue is that you are sending the data via query parameters, and not in the body.

You need to send RAW JSON in the body like so:

Screenshot_2023-11-23_101159

5 Likes

Thank you very much @samliew !!
That does the trick :slight_smile:

2 Likes

Aaaaah - thanks for spotting!

2 Likes