How to Dynamically Pass Credentials to the Google Gemini Chat Model in n8n?

Hello everyone,

I’m working on a project to build an automated SEO analysis tool in n8n that uses the Gemini API. The key requirement is for each user to use their own Gemini API key, which is passed dynamically in a webhook payload.

I’ve successfully created a workflow that takes the user’s API key from the webhook and calls the Gemini API directly using the HTTP Request node. This works perfectly, and I can get a correct analysis report.

However, this approach forces me to lose the powerful built-in features of the AI Agent node, such as Memory and Tools. These features are essential for future enhancements of the tool.

Is there a way to dynamically pass credentials (the API key from the webhook) to the dedicated Google Gemini Chat Model node? I’ve checked the node’s settings, and the credential field seems to only accept static credentials saved in n8n’s credential store, with no option for a dynamic expression.

Any insights or alternative solutions would be greatly appreciated. Thank you!

1 Like

Hi @fatiimahoseini , Yes, you can make this work. While the Gemini Chat Model node only lets you pick a saved credential, the API Key field inside that credential supports expressions.

So you can create one credential (e.g. “Gemini Dynamic Key”) and in its API Key field set an expression like:

At runtime, the value from your webhook will be used as the API key, and the Gemini Chat Model node will run with it.

2 Likes

This solved my problem, Thank you so much!

1 Like