» pip install google-generativeai
Videos
Gemini is a large language model as you specified. You can use it (via API calls) by calling either Google AI APIs or Vertex AI APIs.
If you are relatively new to Gemini and wants to explore the feature and build some prototype for your chatbot app, Google AI APIs (with Google AI Studio) is a fast way to get started. While your app and idea matures and you'd like to leverage more MLOps tools that streamline the usage, deployment, and monitoring of models, you can move to Google Cloud Vertex AI which provides Gemini APIs along with many other features. Basically, to help you productionize your app.
Depending on your app requirement and stages of your development, you can choose the path:
- Start with Google AI Studio and migrate Gemini app to Vertex AI
- Prototype and build with Vertex AI if you already have GCP established.
Pay attention to the Google AI vs. Vertex AI differences when making decision.
Update (2025):
Google released a new GenAI SDK that provides a unified interface to Gemini >2.0models through both the Gemini Developer API and the Gemini API on Vertex AI. With a few exceptions, code that runs on one platform will run on both. This means that you can prototype an application using the Gemini Developer API and then migrate the application to Vertex AI without rewriting your code.
Detail see here.
Updated answer in Aug 2025
Significant changes have been introduced in 2025. Google has released a new Google GenAI SDK, that allows to switch between Google Gemini and Gemini on Vertex AI.
Here is a code samples for your
Copyimport {GoogleGenAI} from '@google/genai';
const GEMINI_API_KEY = process.env.GEMINI_API_KEY;
const ai = new GoogleGenAI({apiKey: GEMINI_API_KEY}); # Using Google Gemini
async function main() {
const response = await ai.models.generateContentStream({
model: 'gemini-2.0-flash-001',
contents: 'Write a 100-word poem.',
});
for await (const chunk of response) {
console.log(chunk.text);
}
}
main();
To change this code to use Gemini on Vertex
Copy
const ai = new GoogleGenAI({ # Using Gemini on Vertex AI
vertexai: true,
project: 'your_project',
location: 'your_location',
apiVersion: 'v1'
});
Tip: If you are planning to use Gemini on Vertex AI, I recommend check Global Endpoint.
To make this code more portable, you also set required config in Environment Variables. Check: https://www.npmjs.com/package/@google/genai or https://github.com/googleapis/js-genai