Skip to content

feat(Truefoundry Chat Model Node): Add Truefoundry AI Gateway integration#21739

Open
venkat1924 wants to merge 5 commits inton8n-io:masterfrom
venkat1924:add-truefoundry-node
Open

feat(Truefoundry Chat Model Node): Add Truefoundry AI Gateway integration#21739
venkat1924 wants to merge 5 commits inton8n-io:masterfrom
venkat1924:add-truefoundry-node

Conversation

@venkat1924
Copy link

@venkat1924 venkat1924 commented Nov 11, 2025

Summary

Add new Truefoundry Chat Model node for n8n's LangChain integration:

  • Add TruefoundryApi credentials with custom header support
  • Implement LmChatTruefoundry node with OpenAI-compatible API
  • Add dynamic model loading via Truefoundry AI Gateway
  • Support all standard chat model options (temperature, maxTokens, etc.)
  • Include response format options (text/JSON) with appropriate warnings
  • Include SVG icons for light and dark themes

The node uses ChatOpenAI from @langchain/openai to communicate with Truefoundry's AI Gateway, which provides a unified interface to multiple LLM providers.

https://www.loom.com/share/3952360f80cb4031ad82c9493ba14306

Related Linear tickets, Github issues, and Community forum posts

Review / Merge checklist

  • PR title and summary are descriptive. (conventions)
  • Docs updated or follow-up ticket created.
  • Tests included.
  • PR Labeled with release/backport (if the PR is an urgent fix that needs to be backported)

Note

Introduces a Truefoundry Chat Model node with dynamic model listing, custom headers/metadata, and full chat options, plus new Truefoundry credentials and tests/assets.

  • LLM Node:
    • Add nodes/llms/LmChatTruefoundry/LmChatTruefoundry.node.ts using ChatOpenAI against Truefoundry AI Gateway.
    • Supports model list/ID, penalties (frequencyPenalty, presencePenalty), temperature, topP, maxTokens, timeout, maxRetries, responseFormat (text/JSON), and reasoningEffort.
    • Sends headers via configuration.defaultHeaders, including X-TFY-METADATA (user email) and optional custom credential header; uses proxy agent; tracing and retry handler wired.
  • Model Loading:
    • Add methods/loadModels.ts to list all models from openai.models.list() against Truefoundry baseURL, with filtering, sorting, proxy, and optional custom headers.
    • Extensive tests for model search behavior and header handling.
  • Credentials:
    • Add credentials/TruefoundryApi.credentials.ts with API key, base URL override, and optional custom header injection; includes /models test request.
  • Tests & Assets:
    • Add unit tests for node configuration/headers/options and load models.
    • Add icons truefoundry.svg and truefoundry.dark.svg.
  • Packaging:
    • Register new credential and node in package.json exports.

Written by Cursor Bugbot for commit 87756b7. This will update automatically on new commits. Configure here.

@CLAassistant
Copy link

CLAassistant commented Nov 11, 2025

CLA assistant check
All committers have signed the CLA.

@n8n-assistant n8n-assistant bot added community Authored by a community member in linear DEPRECATED labels Nov 11, 2025
@n8n-assistant
Copy link
Contributor

n8n-assistant bot commented Nov 11, 2025

Hey @venkat1924,

Thank you for your contribution. We appreciate the time and effort you’ve taken to submit this pull request.

Before we can proceed, please ensure the following:
• Tests are included for any new functionality, logic changes or bug fixes.
• The PR aligns with our contribution guidelines.

Regarding new nodes:
We no longer accept new nodes directly into the core codebase. Instead, we encourage contributors to follow our Community Node Submission Guide to publish nodes independently.

If your node integrates with an AI service that you own or represent, please email nodes@n8n.io and we will be happy to discuss the best approach.

About review timelines:
This PR has been added to our internal tracker as "GHC-5446". While we plan to review it, we are currently unable to provide an exact timeframe. Our goal is to begin reviews within a month, but this may change depending on team priorities. We will reach out when the review begins.

Thank you again for contributing to n8n.

@venkat1924 venkat1924 marked this pull request as ready for review November 17, 2025 17:27
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

This PR is being reviewed by Cursor Bugbot

Details

Your team is on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle for each member of your team.

To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

Copy link
Contributor

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

Choose a reason for hiding this comment

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

4 issues found across 6 files

Prompt for AI agents (all 4 issues)

Understand the root cause of the following 4 issues and fix them.


<file name="packages/@n8n/nodes-langchain/nodes/llms/LmChatTruefoundry/LmChatTruefoundry.node.ts">

<violation number="1" location="packages/@n8n/nodes-langchain/nodes/llms/LmChatTruefoundry/LmChatTruefoundry.node.ts:18">
Rule violated: **Tests**

This new Truefoundry chat model node adds production functionality without any accompanying tests, violating the Community PR Guidelines that require unit/workflow tests for node changes. Please add the appropriate tests covering the node&#39;s core behavior before merging.</violation>

<violation number="2" location="packages/@n8n/nodes-langchain/nodes/llms/LmChatTruefoundry/LmChatTruefoundry.node.ts:239">
Rule violated: **Prefer Typeguards over Type casting**

`credentials.url` and `credentials.apiKey` are being narrowed with `as string`, which violates the Prefer Typeguards over Type casting rule and bypasses TypeScript safety. Please validate these credential fields (or tighten their typings) before using them so the compiler enforces the invariant instead of relying on assertions.</violation>

<violation number="3" location="packages/@n8n/nodes-langchain/nodes/llms/LmChatTruefoundry/LmChatTruefoundry.node.ts:251">
`evaluateExpression` already returns the resolved JSON string (e.g. `{&quot;x-n8n-user&quot;:&quot;...&quot;}`) without a leading `=`, so this guard is always false and the X-TFY-METADATA header is never sent.</violation>
</file>

<file name="packages/@n8n/nodes-langchain/nodes/llms/LmChatTruefoundry/methods/loadModels.ts">

<violation number="1" location="packages/@n8n/nodes-langchain/nodes/llms/LmChatTruefoundry/methods/loadModels.ts:11">
Rule violated: **Prefer Typeguards over Type casting**

Casting the credential fields to `string` with `as` sidesteps the required type guard/annotation and can hide missing or malformed credential values. Please narrow these values with runtime checks (or adjust typings) before using them instead of relying on assertions.</violation>
</file>

Since this is your first cubic review, here's how it works:

  • cubic automatically reviews your code and comments on bugs and improvements
  • Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
  • Ask questions if you need clarification on any suggestion

Reply to cubic to teach it or ask questions. Re-run a review with @cubic-dev-ai review this PR

…tion

Add new Truefoundry Chat Model node for n8n's LangChain integration:

- Add TruefoundryApi credentials with custom header support
- Implement LmChatTruefoundry node with OpenAI-compatible API
- Add dynamic model loading via Truefoundry AI Gateway
- Support all standard chat model options (temperature, maxTokens, etc.)
- Include response format options (text/JSON) with appropriate warnings
- Include SVG icons for light and dark themes

The node uses ChatOpenAI from @langchain/openai to communicate with Truefoundry's AI Gateway, which provides a unified interface to multiple LLM providers.
…odel node

- Add 18 unit tests for LmChatTruefoundry node covering:
  - Node description and configuration
  - Credentials handling (API key, URL, custom headers)
  - X-TFY-METADATA header with user email evaluation
  - All available options (frequency penalty, max tokens, temperature, etc.)
  - Response format and reasoning effort options
  - N8nLlmTracing callback and failed attempt handler
  - Edge cases and default values

- Add 13 unit tests for searchModels method covering:
  - OpenAI client initialization
  - Model listing and filtering
  - Custom headers support
  - Case-insensitive search
  - Alphabetical sorting
  - Edge cases

- Fix evaluateExpression call in node (remove `=` prefix)

All 31 tests pass. Tests follow n8n conventions and match patterns
from other langchain nodes (OpenAI, Anthropic).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community Authored by a community member in linear DEPRECATED

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants