How to Access and Use Google Gemini API Key (with Examples)

AfterGemini AI’s announcement, Google has released API access for its Gemini models. Currently, the company is offering API access to Gemini Pro, including text-only and text-and-vision models. It’s an interesting release because so far, Google has not added the visual capability to Bard as it is running the text-only model. With this API key, you can finally testGemini’s multimodal capabilityon your computer locally right away. On that note, let’s learn how to access and use the Gemini API in this guide.

Note:The Google Gemini API key is free for now for both text and vision models. It will be free until general availability early next year. So, you can send up to 60 requests per minute without having to set up Google Cloud billing or incurring any costs.

Set Up Python and Pip on Your Computer

Set Up Python and Pip on Your Computer

How to Get the Gemini Pro API Key

How to Get the Gemini Pro API Key

How to Use the Gemini Pro API Key (Text-only Model)

Similar to OpenAI, Google has made it straightforward to use its Gemini API key for development and testing purposes. I have made the code pretty simple for the general user to test and use it. In this example, I demonstrate how to use the Gemini Pro Text model through the API key.

How to Use the Gemini Pro API Key (Text-and-Vision Model)

In this example, I am going to show how you can interact with the Gemini Pro multimodal model. It’s not live on Google Bard yet, but through the API, you can access it right away. And thankfully, the process is again quite easy and seamless.

How to Use the Gemini Pro API Key in Chat Format

Thanks tounconv’s(GitHub) concise code, you can chat with the Gemini Pro model in the Terminal window using a Gemini AI API key. This way, you don’t have to change the question in the code and rerun the Python file to get a new output. You can continue the chat in the Terminal window itself.

Best of all, Google has natively implemented chat history so you don’t need to manually append the responses andmanage a chat history on your ownin an array or a list. With a simple function, Google stores all the conversation history in a chat session. Here is how it works.

So these are a few examples you can try to check out Google Gemini’s capabilities through the API. I like the fact that Google has made its vision model available for enthusiasts and developers to give it a try, comparing it to OpenAI’s DALL-E 3 and ChatGPT. While the Gemini Pro vision model doesn’t beat the GPT-4V model, it’squite goodnonetheless. We are waiting for the Gemini Ultra’s launch which is on par with the GPT-4 model.

Apart from that, the responses from the Gemini Pro API feel a bit different from Google Bard, which is also powered by a finetuned version of Gemini Pro. Bard’s responsesseem slightlyboring and sanitized, but Gemini Pro’s API responses feel more lively and have character.

We will be tracking all the changes in this space, so stay tuned for more Gemini AI-related content. Meanwhile, go ahead and check out the Google Gemini API by yourself.

Arjun Sha

Passionate about Windows, ChromeOS, Android, security and privacy issues. Have a penchant to solve everyday computing problems.

Add new comment

Name

Email ID

Δ

01

02

03

04

05