Google recently released gemini-cli, which is an REPL like interface for google's Gemini AI, they are quite generous with their free usage policies (ie. 60 requests per minute, 1K requests per day) and as it is commandline based, you can use this in node-red (if you are willing to accept their terms ofcourse :') )
I am using node-red on a headless server, but google authentication is done via a browser which is not available. This is a small tutorial to make this work on a remote server without a browser:
- Open 2 terminal windows on your remote machine (both on same host as your node-red instance)
npm install -g @google/gemini-cli
gemini --debug
- In the output, look for the url like:
https://accounts.google.com/o/oauth2/v2/auth?XXXXXXXXXXX
- Copy/open this URL in a browser
- This will result in a error (can't find the page). Find the port number in the redirect_uri parameter. For example, if redirect_uri is
http://localhost:21165/oauth2callback?...
, the port is21165
.- In the 2nd terminal window:
ssh -L 21165:0.0.0.0:21165 <your current username>@<ip of this host>
(use the same port number that was returned in 5)
example:ssh -L 21165:0.0.0.0:21165 pi@192.168.1.30
- Try to open the url from 4 again
- You should now redirected to google account and can complete the authorisation
If it does not authenticate, try to open the same URL as in 6, change 'localhost' to the ip address of the remote server you are running the terminal from in 7.
You should now be able to complete the authorisation and use gemini-cli
/quit
to exit
You can now use it non-interactively by invoking the -p
argument (prompt); gemini -p "hello"
This means you can use it inside node-red flow using an exec node:
For the gemini command in the exec node, you may need to use the full path to the gemine command: via the cli: which gemini
use the result in the exec node instead. The output will require some parsing here and there. In the weather example above, gemini-cli uses websearch tools by default, which is quite useful for realtime results.
Keep in mind that it is not fast with its responses because it uses reasoning (ie, ±20 seconds)