LangChain.js and Gemini: Getting Started

Allen Firstenberg
14 min readJun 5, 2024

In this tutorial, we will go over the two platforms you can use to run Gemini, the Google AI Studio API (sometimes called the “Gemini API”) and on Google Cloud’s Vertex AI platform. These two platforms support different authentication methods. We’ll look at the different methods available, when to best use each, and how. Finally, we’ll look at some code and see how this all fits into the LangChain.js architecture.

If you’re eager — you can skip ahead to the code section to see what it will look like. But be sure to return to the top to understand how to pick a platform and authentication method.

Where Gemini runs

The Gemini family of models from Google form the underlying infrastructure for a number of different products. We won’t be focusing on all these platforms, but for more info you can check out the article I’ve already written about them.

As developers, we are focusing specifically on those in blue since we can access them using LangChain.js. In particular, we are focusing on the two platforms that let us use an API to access the Gemini model:

Gemini works quite similarly on these two platforms. The LangChain.js classes hide most of the differences between the two. So you can switch from one platform to the other. If you’re familiar with OpenAI’s access…

--

--