Skip to content

fix(core): Include custom headers when loading OpenAI models (backport to release-candidate/2.14.x) - #27539

Closed
n8n-assistant[bot] wants to merge 1 commit into
release-candidate/2.14.xfrom
backport-27534-to-release-candidate/2.14.x
Closed

n8n-assistant[bot] wants to merge 1 commit into
release-candidate/2.14.xfrom
backport-27534-to-release-candidate/2.14.x

Conversation

@n8n-assistant

@n8n-assistant n8n-assistant Bot commented Mar 25, 2026

Copy link
Copy Markdown
Contributor

Description

Backport of #27534 to release-candidate/2.14.x.

Checklist for the author (@Cadiac) to go through.

  • Review the backport changes
  • Fix possible conflicts
  • Merge to target branch

After this PR has been merged, it will be picked up in the next patch release for release track.

Original description

Summary

We were not including custom headers from OpenAI (compatible) credentials when loading models on Chat hub and on canvas node details view resource locators.

This PR fixes that, and changes us to properly include custom headers on OpenAI loadModels calls.

Related Linear tickets, Github issues, and Community forum posts

https://linear.app/n8n/issue/CHA-171/chathub-model-selector-missing-mergecustomheaders-custom-credential

Review / Merge checklist

  • 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)

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

Architecture diagram
sequenceDiagram
    participant UI as Chat Hub / Canvas UI
    participant Server as n8n Backend (searchModels)
    participant Creds as Credential Store
    participant Config as AiConfig (DI Container)
    participant SDK as OpenAI SDK Client
    participant API as OpenAI (or Compatible) API

    Note over UI, API: Fetching Models for Model Selector

    UI->>Server: Request model list (loadOptions)
    
    Server->>Creds: getCredentials()
    Creds-->>Server: apiKey, custom headers (headerName, headerValue)
    
    Server->>Config: Get openAiDefaultHeaders
    Config-->>Server: global default headers
    
    Note over Server: NEW: mergeCustomHeaders(credentials, globalHeaders)
    Server->>Server: Build final header object
    
    Server->>SDK: NEW: Initialize with baseURL & defaultHeaders
    
    Server->>SDK: listModels()
    SDK->>API: GET /models (with custom headers)
    
    alt API Success
        API-->>SDK: List of models
        SDK-->>Server: Model data
        Server->>Server: Filter & sort models
        Server-->>UI: Return INodeListSearchResult[]
    else API Error (e.g., 401/403)
        API-->>SDK: Error response
        SDK-->>Server: Throw Exception
        Server-->>UI: Return empty list / Error toast
    end
Loading

@Cadiac
Cadiac enabled auto-merge (squash) March 25, 2026 09:18
@codecov

codecov Bot commented Mar 25, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.33333% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...hain/nodes/llms/LMChatOpenAi/methods/loadModels.ts 83.33% 0 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@Matsuuu
Matsuuu deleted the branch release-candidate/2.14.x May 8, 2026 05:48
@Matsuuu Matsuuu closed this May 8, 2026
auto-merge was automatically disabled May 8, 2026 05:48

Pull request was closed

@Matsuuu
Matsuuu deleted the backport-27534-to-release-candidate/2.14.x branch June 2, 2026 11:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automation:backport n8n team Authored by the n8n team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants