Error connecting OpenAI API in n8n cloud – config.headers.setContentType is not a function

Title: Error connecting OpenAI API in n8n – config.headers.setContentType is not a function

Hello everyone,

I’m having trouble connecting the OpenAI API in n8n.

I tested this on both versions:

  • Stable version

  • Latest Beta version (2.20.6)

In both cases, I get the same error when trying to save the OpenAI credentials:

Couldn't connect with these settings
config.headers.setContentType is not a function

What I already tried:

  • Generated a new OpenAI API key

  • Updated n8n to the latest beta version

  • Tested with and without Organization ID

  • Retried the connection multiple times

Current issue:

  • I cannot register/connect the OpenAI API credentials inside n8n

  • I also tried using the HTTP Request node as an alternative, but I couldn’t make it work (probably missing the correct configuration)

Has anyone experienced this issue before?
Could someone share:

  1. A possible fix for this error

  2. A step-by-step example using the HTTP Request node to connect to OpenAI API

Thank you very much for any help!

The n8n team is already aware of this issue
Please keep a lookout for any updates

@ademilson_assuncao known interceptor bug (#29471), URL match on api.openai.com so nothing your side will fix it. quick unblock is a tiny cloudflare worker proxy, point the HTTP Request node at it:

export default { async fetch(req) { const u = new URL(req.url); u.host = 'api.openai.com'; return fetch(new Request(u, req)); } }

then hit https://yourworker.workers.dev/v1/chat/completions with the Bearer header, passes through clean

Hey @ademilson_assuncao, welcome to the community! Really thorough first post with all the details, makes it much easier to help.

Just to add a bit more context on top of what was shared above:

This is a confirmed bug (GitHub issue #29471) in n8n 2.19.x, specifically in the axios request interceptor. When n8n detects a URL starting with api.openai.com, it rewrites the headers object, and that breaks the setContentType method. It affects the credential test, HTTP Request node, and AI nodes when they all point to OpenAI’s domain.

The quickest workarounds while waiting for the official fix:

  1. Just save the credential anyway - the error shows on the credential test, but the credential itself often works fine in the actual workflow. When using the OpenAI node, pick your model “By ID” and type the model name manually (like gpt-4o or gpt-4o-mini).

  2. If you’re self-hosted on Docker, pin to version 2.18.5 in your compose file until a patch drops.

  3. For n8n Cloud users, you’re stuck waiting for n8n to push the fix (it’s tracked and assigned). You can subscribe to the GitHub issue for updates: HTTP Request node fails with "config.headers.setContentType is not a function" when calling api.openai.com · Issue #29471 · n8n-io/n8n · GitHub

Hope that clears things up!