n8n - ✅(Solved) Fix HTTP Request node fails with "config.headers.setContentType is not a function" when calling api.openai.com [1 pull requests, 1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
n8n-io/n8n#29471Fetched 2026-04-30 06:44:11
View on GitHub
Comments
1
Participants
2
Timeline
7
Reactions
0
Timeline (top)
labeled ×3commented ×1cross-referenced ×1mentioned ×1

Error Message

The HTTP Request node throws NodeApiError: config.headers.setContentType is not a function when the request URL starts with https://api.openai.com/. The error originates inside the global axios request interceptor in packages/core/src/execution-engine/node-execution-context/utils/request-helpers/axios-config.ts at line 30:

  • error: all

Root Cause

A minimal workflow JSON that reproduces the issue (single "Get models" node hitting https://api.openai.com/v1/models) is enough; no credentials are required because the failure happens before the request leaves the instance.

Fix Action

Fixed

PR fix notes

PR #26852: refactor(core): Extract global axios config into axios-config.ts (no-changelog)

Description (problem / solution / changelog)

Summary

PR 1/X to break request-helpers into more modular parts.

Extracts global axios configuration side effects and related helper functions from the monolithic request-helper-functions.ts into dedicated files under request-helpers/ directory. This improves code organization and makes side effects explicit.

Changes:

  • Created axios-config.ts containing axios defaults setup and request interceptor
  • Created utils.ts exporting pure helper functions: getUrlFromProxyConfig, buildTargetUrl, setAxiosAgents, applyVendorHeaders
  • Added comprehensive unit tests (20 test cases) for the extracted utility functions
  • Cleaned up unused imports in the original file

Related Linear tickets, Github issues, and Community forum posts

https://linear.app/n8n/issue/CAT-2582

Review / Merge checklist

  • PR title and summary are descriptive
  • Tests included (20 unit tests for extracted utilities)
  • Docs updated (N/A - internal refactoring)

Changed files

  • packages/core/src/execution-engine/node-execution-context/utils/request-helper-functions.ts (modified, +8/-102)
  • packages/core/src/execution-engine/node-execution-context/utils/request-helpers/__tests__/utils.test.ts (added, +182/-0)
  • packages/core/src/execution-engine/node-execution-context/utils/request-helpers/axios-config.ts (added, +46/-0)
  • packages/core/src/execution-engine/node-execution-context/utils/request-helpers/utils.ts (added, +78/-0)

Code Example

if (config.data === undefined) {
      config.headers.setContentType(false, false);
  }

---

config.headers = {
      ...Container.get(AiConfig).openAiDefaultHeaders,
      ...(config.headers ?? {}),
  };
RAW_BUFFERClick to expand / collapse

Bug Description

The HTTP Request node throws NodeApiError: config.headers.setContentType is not a function when the request URL starts with https://api.openai.com/. The error originates inside the global axios request interceptor in packages/core/src/execution-engine/node-execution-context/utils/request-helpers/axios-config.ts at line 30:

  if (config.data === undefined) {
      config.headers.setContentType(false, false);
  }

The interceptor assumes config.headers is an AxiosHeaders instance, but applyVendorHeaders (lines 39–46 in the same file) reassigns config.headers to a plain object literal whenever the URL targets OpenAI:

  config.headers = {
      ...Container.get(AiConfig).openAiDefaultHeaders,
      ...(config.headers ?? {}),
  };

Plain objects don't expose setContentType, so any downstream invocation of the interceptor on that mutated config (including the path triggered by the V3 HTTP Request node when sending no body) raises the TypeError, which is caught and rewrapped as NodeApiError at HttpRequestV3.node.js:588.

To Reproduce

  1. Create a workflow with an HTTP Request node (typeVersion 4.2).
  2. Set: - Method: GET - URL: https://api.openai.com/v1/models - Authentication: None - Send Headers: true, with Authorization: Bearer <key> and OpenAI-Organization: <org> (I think this second header may be optional for reproducibility).
  3. Execute the workflow.
  4. The node fails with NodeApiError: config.headers.setContentType is not a function.

A minimal workflow JSON that reproduces the issue (single "Get models" node hitting https://api.openai.com/v1/models) is enough; no credentials are required because the failure happens before the request leaves the instance.

Expected behavior

The HTTP Request node should successfully reach https://api.openai.com/v1/models (or whichever OpenAI endpoint), receive the response from OpenAI, and surface it as the node output. The interceptor should not throw, regardless of whether applyVendorHeaders rewrites the headers as a plain object or an AxiosHeaders instance.

Debug Info

Debug info

core

  • n8nVersion: 2.19.0
  • platform: docker (self-hosted)
  • nodeJsVersion: 22.21.0
  • nodeEnv: production
  • database: postgres
  • executionMode: scaling (single-main)
  • concurrency: 60

storage

  • success: all
  • error: all
  • progress: false
  • manual: false
  • binaryMode: filesystem

pruning

  • enabled: true
  • maxAge: 336 hours
  • maxCount: 5000 executions

security

  • blockFileAccessToN8nFiles: false

Generated at: 2026-04-29T10:07:45.227Z

Operating System

N/A

n8n Version

2.19.0

Node.js Version

22.21.0

Database

PostgreSQL

Execution mode

queue

Hosting

self hosted

extent analysis

TL;DR

The issue can be fixed by ensuring that config.headers is an instance of AxiosHeaders before calling setContentType on it.

Guidance

  • Verify that applyVendorHeaders is reassigning config.headers to a plain object literal when the URL targets OpenAI, which causes the error.
  • Check if config.headers can be initialized as an AxiosHeaders instance before the interceptor is called.
  • Consider modifying the axios-config.ts file to ensure that config.headers is always an AxiosHeaders instance, even after applyVendorHeaders is called.
  • Test the fix by reproducing the issue with the modified code and verifying that the HTTP Request node successfully reaches the OpenAI endpoint.

Example

// Ensure config.headers is an AxiosHeaders instance
config.headers = new AxiosHeaders(config.headers);

This code snippet can be added before the line that calls setContentType on config.headers.

Notes

The fix may require modifications to the axios-config.ts file, which could have unintended consequences on other parts of the application. Thorough testing is recommended to ensure that the fix does not introduce new issues.

Recommendation

Apply a workaround by modifying the axios-config.ts file to ensure that config.headers is always an AxiosHeaders instance, as this is the most direct way to fix the issue.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

The HTTP Request node should successfully reach https://api.openai.com/v1/models (or whichever OpenAI endpoint), receive the response from OpenAI, and surface it as the node output. The interceptor should not throw, regardless of whether applyVendorHeaders rewrites the headers as a plain object or an AxiosHeaders instance.

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

n8n - ✅(Solved) Fix HTTP Request node fails with "config.headers.setContentType is not a function" when calling api.openai.com [1 pull requests, 1 comments, 2 participants]