Getting Started with the Gemini Pro API

This guide explores how to obtain an API key and get started with the Gemini Pro SDKs.

On December 6, 2023, Google unveiled its long-awaited GPT-4 rival Gemini. The model comes in three variants, Gemini Nano to run on edge (laptops, phones, devices, etc.), Gemini Pro powering Google's Bard chatbot, and a yet-to-be-released Gemini Ultra allegedly topping GPT-4 on industry benchmarks.

Gemini Pro also comes with an API, which means it can be integrated inside any AI-powered product. Let's explore how to do that.

Getting an API key

Google gives access to the Gemini Pro API as part of their Google AI Studio product. You will need to sign up for this free product to get an API key.

Individual Google account

If you have an individual Google account (i.e. you are not part of an organization's workspace), you can simply go to and click "Get API key in Google AI Studio".

Then click "Get API key".

Then, depending on whether you already have a GCP project click either of the two options. If you don't have a project, Google will create one for you automatically.

An API key will be create, copy it and paste it in a safe location as you will not be able to see it again later.

Google Workspace account

If your Google account is part of a Workspace account (e.g. you are using a work email) your Workspace admin will need to activate Early Access Apps before you can follow the above steps.

Workspace admins should navigate to the Admin Console and find "Additional Google Services" in the left menu.

Then scroll down to "Early Access Apps" and click on it.

Enable it for everyone:

And also enable Core Data Access Permissions. You will not be able to get an API key without this enabled.

Once this is complete, you should be able to follow the steps in the Individual Account section to get your API key.

Integrating Gemini Pro in your application

Once you have obtained an API key and saved it in a safe place, you can start integrating the Gemini Pro API in your application.

There are multiple options depending on your stack.

Raw HTTP requests

The most versatile way to query the Gemini Pro API is via direct HTTP requests:

Python SDK

If your app is in Python, Google offers a handy Python SDK to interact with the API. The documentation can be found here.

Install the SDK:

And use it as such:

Typescript SDK

If your poison of choice is Typescript, Google's got you covered too. Find the documentation here.

Install the library:

Then use it as such:

Other languages

If your using other languages such as Go or Swift, find all Google's SDKs here.

API differences with OpenAI

Note that the query and response payloads for OpenAI and Gemini Pro's APIs are different.

Query payloads

OpenAI's query payload looks like this:

while Gemini Pro's looks like this:

Notice these three main differences:

  • OpenAI expects the model name as part of the payload whereas Gemini Pro has different endpoints for different models
  • OpenAI refers to messages as messages whereas Gemini calls them contents
  • OpenAI roles refer to the model as assistant while Gemini uses model

Response payloads

Response payloads are also quite different between OpenAI and Gemini's APIs.

OpenAI's response payloads reads:

whereas Gemini's reads:

Note that Gemini returns many safety metrics, which you can also configure thresholds for at query time.

The Airtrain Al Youtube channel

Subscribe now to learn about Large Language Models, stay up to date with Al news, and discover Airtrain Al's product features.

Subscribe now