Secure your Gemini AI API Key with Google Cloud Restrictions

Andres Sandoval
6 min readMar 8, 2024

This tutorial guides you through adding Google Cloud restrictions to the Gemini AI API within your Android app. Google Cloud acts as the backbone for the Gemini API and offers settings to restrict API requests.

These restrictions provide an essential layer of security and control. By leveraging this feature, you can limit which platforms are authorized to access your API key, safeguarding your company and developers in case of compromised credentials and potential misuse.

Android Studio offers a convenient Gemini template app. Simply create a new app using this template, input your Gemini API key, build your Android app, and you’re ready to leverage the power of Gemini AI.

How to get the Gemini API key

Get the Gemini API key here: https://aistudio.google.com/app/apikey. The Gemini API documentation might also offer guidance on obtaining and managing API keys. You can find the documentation here: https://developers.google.com/focus/ai-development

aistudio.google.com/app/apikey

Managing Your API Key and Monitoring Activity:

Upon creating a new API key, it becomes automatically managed within Google Cloud. This platform provides you with access to:

  • API Key Management: View, or delete your API key as…

--

--