n8n - ✅(Solved) Fix Add OpenAI OAuth credential support for OpenAI Chat Model nodes [2 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#29180Fetched 2026-04-28 06:49:29
View on GitHub
Comments
1
Participants
2
Timeline
4
Reactions
0
Timeline (top)
closed ×1commented ×1cross-referenced ×1labeled ×1

Fix Action

Fixed

PR fix notes

PR #29184: feat(OpenAI Chat Model Node): Add OpenAI account OAuth support

Description (problem / solution / changelog)

Summary

Add OpenAI account OAuth support to the OpenAI Chat Model node while keeping the existing API key credential path unchanged.

This adds a dedicated OpenAI Account (ChatGPT) credential and lets the OpenAI Chat Model node choose between API key and OAuth2 authentication. The OAuth2 credential stays aligned with n8n's existing credential UX: users still use the standard Connect button and popup/BroadcastChannel flow, while the popup hosts OpenAI's device-code login flow instead of asking users to paste an access token manually.

OpenAI account tokens cannot call the public OpenAI Responses API directly, so OAuth-backed chat model execution uses the ChatGPT/Codex account backend and maps LangChain messages, streaming chunks, tool calls, tool results, model discovery, and reasoning effort into that protocol. API key execution continues to use the existing OpenAI/LangChain path.

OpenAI-specific credential UI is kept small: the OAuth redirect URL and HTTP Request domain restriction controls are hidden for this credential because they do not apply to the device-code flow.

Related Linear tickets, Github issues, and Community forum posts

No Linear ticket is linked because this is an external contribution and I do not have access to the n8n Linear workspace. The GitHub issue was auto-closed because n8n uses GitHub issues for bugs only, but it is kept here as public context for this contribution.

Review / Merge checklist

  • I have seen this code, I have run this code, and I take responsibility for this code.
  • PR title and summary are descriptive. (conventions)
  • Docs updated or follow-up ticket created.
  • Tests included.
  • PR Labeled with Backport to Beta, Backport to Stable, or Backport to v1 (if the PR is an urgent fix that needs to be backported)

Validation

  • pushd packages/nodes-base && pnpm test OpenAiApi.credentials.test.ts --runInBand && popd
  • pushd packages/@n8n/nodes-langchain && pnpm test LmChatOpenAi.test.ts OpenAiAccountChatModel.test.ts LMChatOpenAi/methods/__tests__/loadModels.test.ts --runInBand && popd
  • pushd packages/cli && pnpm test openai-oauth2-device.controller.test.ts oauth2-credential.controller.test.ts load-nodes-and-credentials.test.ts --runInBand && popd
  • pushd packages/frontend/editor-ui && pnpm vitest run src/features/credentials/components/CredentialEdit/CredentialEdit.test.ts src/features/credentials/components/CredentialEdit/CredentialConfig.test.ts && popd
  • pushd packages/nodes-base && NODE_OPTIONS=--max-old-space-size=8192 pnpm lint && popd
  • pushd packages/@n8n/nodes-langchain && pnpm lint && popd
  • pushd packages/cli && NODE_OPTIONS=--max-old-space-size=8192 pnpm lint && popd
  • pushd packages/frontend/editor-ui && pnpm lint && popd
  • pushd packages/cli && NODE_OPTIONS=--max-old-space-size=8192 pnpm typecheck && popd
  • pushd packages/@n8n/nodes-langchain && pnpm typecheck && popd
  • pushd packages/nodes-base && pnpm typecheck && popd
  • pushd packages/frontend/editor-ui && pnpm typecheck && popd
  • pnpm build > build.log 2>&1
  • git diff --check origin/master..HEAD
  • Manual local startup and workflow test with OAuth credential on http://localhost:5680

Changed files

  • packages/@n8n/nodes-langchain/nodes/llms/LMChatOpenAi/LmChatOpenAi.node.ts (modified, +170/-38)
  • packages/@n8n/nodes-langchain/nodes/llms/LMChatOpenAi/OpenAiAccountChatModel.ts (added, +1389/-0)
  • packages/@n8n/nodes-langchain/nodes/llms/LMChatOpenAi/methods/__tests__/loadModels.test.ts (modified, +62/-0)
  • packages/@n8n/nodes-langchain/nodes/llms/LMChatOpenAi/methods/loadModels.ts (modified, +98/-3)
  • packages/@n8n/nodes-langchain/nodes/llms/test/LmChatOpenAi.test.ts (modified, +107/-0)
  • packages/@n8n/nodes-langchain/nodes/llms/test/OpenAiAccountChatModel.test.ts (added, +388/-0)
  • packages/cli/src/__tests__/load-nodes-and-credentials.test.ts (modified, +13/-1)
  • packages/cli/src/auth/__tests__/auth-service-browser-id-whitelist.test.ts (modified, +6/-0)
  • packages/cli/src/auth/auth.service.ts (modified, +1/-0)
  • packages/cli/src/controllers/oauth/__tests__/oauth2-credential.controller.test.ts (modified, +21/-0)
  • packages/cli/src/controllers/oauth/__tests__/openai-oauth2-device.controller.test.ts (added, +136/-0)
  • packages/cli/src/controllers/oauth/oauth2-credential.controller.ts (modified, +14/-0)
  • packages/cli/src/controllers/oauth/openai-oauth2-device.controller.ts (added, +457/-0)
  • packages/cli/src/load-nodes-and-credentials.ts (modified, +4/-0)
  • packages/cli/src/server.ts (modified, +1/-0)
  • packages/frontend/editor-ui/src/features/credentials/components/CredentialEdit/CredentialConfig.test.ts (modified, +33/-0)
  • packages/frontend/editor-ui/src/features/credentials/components/CredentialEdit/CredentialConfig.vue (modified, +5/-1)
  • packages/frontend/editor-ui/src/features/credentials/components/CredentialEdit/CredentialEdit.test.ts (modified, +88/-0)
  • packages/frontend/editor-ui/src/features/credentials/components/CredentialEdit/CredentialEdit.vue (modified, +7/-0)
  • packages/frontend/editor-ui/src/features/credentials/components/CredentialIcon.test.ts (modified, +29/-0)
  • packages/frontend/editor-ui/src/features/credentials/components/CredentialIcon.vue (modified, +6/-0)
  • packages/nodes-base/credentials/OpenAiApi.credentials.ts (modified, +25/-1)
  • packages/nodes-base/credentials/OpenAiOAuth2Api.credentials.ts (added, +83/-0)
  • packages/nodes-base/credentials/test/OpenAiApi.credentials.test.ts (modified, +114/-17)
  • packages/nodes-base/package.json (modified, +1/-0)
  • packages/workflow/src/interfaces.ts (modified, +2/-0)
RAW_BUFFERClick to expand / collapse

Feature request

Support OpenAI credentials backed by OAuth access tokens for OpenAI Chat Model nodes, in addition to the existing API key credential path.

Use case

Browser-based and headless credential setup flows can produce an OAuth access token instead of an API key. Today the OpenAI Chat Model and related OpenAI LangChain callers read only apiKey, so those credentials cannot be used directly.

Proposed behavior

  • Extend the existing openAiApi credential with an OAuth access token mode.
  • Resolve tokens from either accessToken or oauthTokenData.access_token to support browser/headless setup outputs.
  • Keep existing API key behavior unchanged.
  • Use the same credential resolution path in OpenAI Chat Model model execution and model discovery.

Additional context

This is intended as an external contribution. I do not have access to the n8n Linear workspace, so there is no Linear ticket reference available.

extent analysis

TL;DR

Extend the existing openAiApi credential to support OAuth access tokens in addition to API keys.

Guidance

  • Identify the current implementation of openAiApi credential and its usage in OpenAI Chat Model nodes to understand the necessary changes.
  • Determine the format and structure of the OAuth access token and how it differs from the existing API key.
  • Update the credential resolution path to support both accessToken and oauthTokenData.access_token for token resolution.
  • Ensure the existing API key behavior remains unchanged and test the new OAuth access token functionality thoroughly.

Example

No code snippet is provided due to the lack of specific implementation details in the issue.

Notes

The proposed change requires careful consideration of security and authentication mechanisms to ensure seamless integration of OAuth access tokens without compromising the existing API key functionality.

Recommendation

Apply workaround by extending the openAiApi credential to support OAuth access tokens, as this allows for a more flexible and secure authentication mechanism for OpenAI Chat Model nodes.

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…

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 Add OpenAI OAuth credential support for OpenAI Chat Model nodes [2 pull requests, 1 comments, 2 participants]