Http request authentication error for the new API responses by openAI

I’m trying to get new model response which has the the web search tool
method POST https://api.openai.com/v1/responses
I’ve set up the header auth with:
Name
Authorization
Value
Bearer my-API

but it keep on giving me error of authentication:

Error code 401
Full message

{
  "error": {
    "message": "Missing bearer or basic authentication in header",
    "type": "invalid_request_error",
    "param": null,
    "code": null
  }
}

these are my body parameters:

{
  "model": "gpt-4o",
  "tools": [
    {
      "type": "web_search_preview",
      "user_location": {
        "type": "approximate",
        "country": "IT"
      }
    }
  ],
  "input": "chi è {{ $json.chatInput }}?"
}

and this are my headers:

[
  {
    "name": "Content-Type",
    "value": "application/json"
  }
]

Do you have some suggestion on how to fix it?
Ps: I can retrieve the response using python and openAI library so the problem is on n8n part

Looking at your error, I think the issue is with your authentication setup in n8n. Even though you mentioned setting up the header auth with “Authentication” as the name and “Bearer my-API” as the value, the error suggests the authentication header isn’t being properly sent.

Here’s how to fix it:

  1. The header name should be Authorization (not Authentication)
  2. Make sure there’s a space between “Bearer” and your API key

Try updating your headers to:

[
  {
    "name": "Content-Type",
    "value": "application/json"
  },
  {
    "name": "Authorization",
    "value": "Bearer sk-youractualapikey"
  }
]

If you’re using the HTTP Request node in n8n, you can also configure the authentication directly in the “Authentication” tab of the node:

  1. Select “Bearer Token” as the authentication type
  2. Enter your OpenAI API key (without the “Bearer” prefix) in the token field

This approach is generally more secure than putting your API key directly in the headers, as n8n will handle the proper formatting of the Authorization header for you.

Or Simply just In your HTTP Request node, under Authentication, you should select Header Auth and manually add a header:
Authorization: Bearer YOUR_API_KEY.
Currently, you only have “Authentication” as the header name, which OpenAI doesn’t recognize.

Thank you masoom for the reply :heart:

yeah I’ve mistakenly written here but I used Authorization correctly.
And I made sure about the space between Bearer and the api key. But it still not working. I tried to use either fixed or expression in the atuthentication just to see if there was a bug in one of them but still didnt work.

I tried with this configuration too but it doenst’t work

the only thing I didn’t try is this one

but I can’t find it in the node Authentication drop menu

What can it be?

I’ve solved using Predifined credential type as Authentication

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.