How to inject dynamic private key (auth) into AI Agent-triggered HTTP tool nodes?

Hey team,
I’m building a workflow using @n8n/langchain AI Agent + HTTP request tool nodes. I want to dynamically inject a privatekey from an auth request into the headers of downstream tool APIs — but I’m hitting roadblocks.


:light_bulb: Goal

When a user selects a tool (like update_meter_status) via AI Agent, n8n should:

  1. Call the authorization_service (returns a privatekey)
  2. Pass that privatekey in the headers of the actual tool request
  3. Not show the auth node (Private Key) in the AI’s tool list/menu

:test_tube: What I’ve Tried (and why it failed)

  • Direct expression:
    ={{ $node["Private Key"].json[0].privatekey }}
    :small_orange_diamond: Fails unless node was already executed → gets undefined or unexecuted error
  • Inline $http() in expression:
    ={{ $http({...}).json[0].privatekey }}
    :small_orange_diamond: Not supported — $http isn’t allowed in expressions
  • Merge node:
    Tried combining AI input + Private Key before tool call
    :small_orange_diamond: Doesn’t trigger both branches, second input usually unexecuted
  • Code node to combine data:
    Merged inputs manually
    :small_orange_diamond: Same issue — one branch unexecuted
  • Renaming node as _internal_ to hide from menu
    :small_orange_diamond: Still appears in AI tool list

:counterclockwise_arrows_button: What I’m Looking For

  • A way to automatically run an internal auth node before any AI-selected tool executes
  • Keep that auth node hidden from tool menu
  • Reuse that privatekey in all downstream HTTP headers

Any clean solutions for this pattern?
Maybe using workflow context, credentials trick, or hidden pre-hooks?

Really appreciate your guidance — happy to share full workflow JSON too!

Thanks :folded_hands: