Gemini API Key
Google's Gemini models are accessible through Google AI Studio for development and prototyping. For production workloads, Google recommends migrating to Vertex AI on Google Cloud. A generous free tier makes Gemini an easy starting point.
Prerequisites
You need the following:
A Google account
Gemini API availability in your region (check during setup)
Step-by-step instructions
Follow the steps to set up the Gemini API key:
Go to aistudio.google.com, click Get started, and then sign in with your Google account.
On the Welcome to AI Studio page, select the I acknowledge that I am a developer... checkbox, and then click Continue.
Click Get API Key on the navigation menu, and then click Create API Key.
In the Create a new key dialog, enter a name in the Name your key field, select a project in the Choose an imported project list, and then click Create key. You can either create the API key in Google Cloud project (recommended for beginners), select an existing project, or create a new project.
Click and copy your API key. Unlike OpenAI and Anthropic, Google AI Studio lets you view the key again later, but it is still best practice to store it immediately.
Optional: Click Set up billing. In the Set up your Google Cloud Billing account dialog, select your country in the Select a country list, and then click Agree & continue.
In Add your billing account details dialog, verify your contact information and selected payment method, then click Submit to finalize your setup.
For new Google Cloud users, an express mode setup provides a free 90-day trial environment with an API key created automatically.
Test Your Key
Store your key as the environment variable GEMINI_API_KEY. Use the Google Gen AI SDK for Python, TypeScript, or Java. You can also test via curl using either the x-goog-api-key header or a query parameter.

Last updated