Google Gemini APIs

Get an overview of Gemini APIs and learn how to set up an API key.

In the era of AI, it has become necessary to access and use the capabilities of LLMs for various applications, from natural language processing to data analysis. One of the most effective and efficient ways to access LLM capabilities is through APIs (Application Programming Interfaces).

Just like the OpenAI API, which provides access to the capabilities of models like GPT-4 in our applications, Google has APIs for accessing the Google Gemini.

Gemini APIs

Google offers two types of APIs to access generative AI capabilities in applications. These offer distinct features and benefits:

  • Google Vertex AI Gemini API

  • Google AI Gemini API

Google Vertex AI Gemini API

The Google Vertex AI Gemini API is part of Google Cloud’s suite of AI services and offers a wide range of functionalities that extend beyond the Gemini model. It integrates with Vertex AI, which is Google’s unified platform for managing and deploying models.

Press + to interact
Google Vertex AI API
Google Vertex AI API

Note: The Gemini API for Vertex AI doesn't use API keys instead it uses identity and access management (IAM) to manage access. We’ll be using the Google AI Gemini API throughout the course. Creating an API key on Vertex AI is optional.

Creating an API key on Vertex AI

Follow these steps to get your Vertex AI API key:

  1. Go to Vertex AI and click the “Try Vertex AI free” button.

  2. Sign up with your account and click the “AGREE & CONTINUE” button.

  3. From the Vertex AI dashboard, search for Vertex AI API and make sure it is enabled.

Press + to interact
Enable the Vertex AI API
Enable the Vertex AI API
  1. Get the project ID by clicking the project name at the top left of the dashboard page.

Press + to interact
Get your project ID
Get your project ID
  1. Get your location from the bottom of the dashboard.

Press + to interact
Get your project location
Get your project location

The project ID and project location are used to access the models in your application’s code.

Google AI Gemini API

The Google AI Gemini API is a REST API that provides access to Google Gemini models. Google AI Gemini API works with both textual and image inputs to generate responses from the different Gemini model variants.

Press + to interact
Gemini API
Gemini API

The table below shows the types of input prompts handled by the different Gemini variants provided by the Google AI Gemini API:

Model

Text

Image

Audio

Video

Code

Output

Gemini 1.0 Pro

Yes

No

No

No

No

Text

Gemini 1.5 Pro

Yes

Yes

Yes

Yes

Yes

Text

Gemini 1.5 Flash

Yes

Yes

Yes

Yes

Yes

Text

Text Embeddings

Yes

No

No

No

No

Text embeddings

AQA

Yes

No

No

No

No

Text

The text embeddings model is used to generate the text embeddings of the textual input data. The AQA model performs Attributed Question-Answering (AQA)-related tasks on text data.

Google AI Gemini API is specifically designed to interact with multimodal state-of-the-art Google Gemini models because it is easy to use, scalable, and has seamless integration.

Since Gemini API uses API keys to manage access, let’s learn to fetch the API key.

Get your API key

Follow these steps to get your Gemini API key:

  1. Login to Google AI Studio using your Google account.

  2. Go to the Get API key page and click the “Create API key” button.

Press + to interact
Create the API key
Create the API key

Make sure to note down your API key to use it in the Jupyter Notebooks.

Using the Google AI Gemini API

Let’s play with the code to get an idea of how the API key allows us to access the Gemini models.

Note: Clic the "Click to launch app!" button in the widget below to launch the Jupyter Notebook. You can also open the Jupyter Notebook in new tab using the button on top-right corner of the widget below.

Please login to launch live app!

Now that we have learned how to access the API key, we will use the Gemini models for different tasks later in the course.