TL;DR: To get a Gemini API key, sign in to Google AI Studio, open Dashboard > API Keys, and copy the key created for your project or create a new one. Save it as the GEMINI_API_KEY environment variable before using it in your application.

You can get a Gemini API key from Google AI Studio. Sign in with your Google Account, select a Google Cloud project, and click Create API key. New users may find that AI Studio has already created a default project and key.

The full process takes only a few minutes. You do not need to search for the key in the regular Gemini chat app or enable billing if you are using an eligible free-tier model.

How to Get a Gemini API Key: Quick Answer

  1. Open Google AI Studio.
  2. Sign in and accept the terms if prompted.
  3. Open Dashboard > API Keys.
  4. Choose or import a Google Cloud project.
  5. Click Create API key and copy the generated key.
  6. Store the key as an environment variable before using it in code.

What Is a Gemini API Key?

A Gemini API key is a private credential that allows an application to access Google's Gemini models through the Gemini Developer API. The key connects each request to a Google Cloud project, where Google tracks permissions, usage limits, and billing.

One key can work with different Gemini models available to the project. You do not need separate keys for Gemini 2.5 Flash, Gemini 2.5 Pro, or other supported models. Your code specifies which model to use.

How to Get a Gemini API Key in 7 Steps

How to get a Gemini Key

1. Open Google AI Studio

Go to the Google AI Studio API Keys page and sign in with your Google Account. Accept Google's terms if this is your first visit.

2. Go to the API Keys Page

Open Dashboard from the left panel and select API Keys. If you are a new user, AI Studio may already display a key connected to a default Google Cloud project. If a key is available, you can copy it and move to Step 5.

3. Choose a Google Cloud Project

Every Google Gemini API key must belong to a Google Cloud project. You can use the default project for testing or choose an existing project for an application that already uses Google Cloud.

If the project is missing, go to Dashboard > Projects > Import projects. Select the project, click Import, and return to the API Keys page. You must have access to the project before you can import it.

4. Create the API Key

Click Create API key and select the project. AI Studio will generate the key and connect it to that project.

New keys created in AI Studio are authorization keys, which Google restricts to the Gemini API by default. If the button is unavailable, ask the project administrator for permission to create API keys and enable services.

5. Copy the Key

Click the copy icon beside the generated key. Do not paste it directly into your source code, a shared document, or a public repository. Treat it like a password.

6. Set the Environment Variable

The Google Gen AI SDK can read the key from GEMINI_API_KEY. On macOS or Linux, add this command to your terminal configuration file:

export GEMINI_API_KEY="YOUR_API_KEY"

Reload the terminal or the configuration file after saving.

On Windows, search and open Environment Variables in System Properties, and click New under User variables. Use GEMINI_API_KEY as the variable name and paste the key as its value. Open a new terminal after saving it.

7. Test the Gemini API Key

Install the Google Gen AI SDK for Python:

pip install -U google-genai

Then run a small request:

from google import genai

client = genai.Client()
response = client.models.generate_content(
    model="gemini-2.5-flash",
    contents="Reply with: The Gemini API key works."
)

print(response.text)

The SDK reads the key from the environment variable. If the script returns a response, the key, project, and selected model are working.

How to Keep a Gemini API Key Secure

  • Store the key in an environment variable during local development.
  • Use a secret manager when deploying the application.
  • Keep .env files out of Git by adding them to .gitignore.
  • Never expose a permanent key in browser or mobile application code.
  • Replace the key immediately if it appears in a public repository or shared message.

Common Gemini API Key Issues

Issue

Likely Cause

Fix

Create API key is unavailable

You lack permission in the Cloud project

Ask the project administrator for the required access.

The project does not appear

It has not been imported into AI Studio

Go to Dashboard > Projects > Import projects.

The SDK cannot find the key

The environment variable is missing, or the terminal has not reloaded

Confirm the GEMINI_API_KEY name and open a new terminal.

API key not valid

The key is incorrect, revoked, or restricted improperly

Copy it again from AI Studio and check the selected project.

429 RESOURCE_EXHAUSTED

The project has reached a rate limit

Wait before retrying or review the project's usage tier.

404 NOT_FOUND

The model name is incorrect or no longer available

Choose a current model from the Gemini models page.

Build expertise in leading AI tools including ChatGPT LangChain, CrewAI, AutoGen, and Claude Code through Simplilearn's Applied Agentic AI program. Through 40+ demos, 10+ guided practices, 7 hands-on projects, and a capstone, you'll gain practical exposure to the technologies shaping the AI-native workplace.

Conclusion

Once the test request returns a response, your Gemini API key is ready to use. Keep it outside your source code and replace it immediately if it is ever exposed. The same key can access any supported Gemini model available to the linked Google Cloud project.

Getting API access is only the starting point. Explore multi-agent systems, RAG, MCP, planning frameworks, and workflow automation through hands-on projects with Simplilearn’s Agentic AI Certification. It is a practical next step if you want to move from making your first API call to designing and deploying complete AI agent systems.

Frequently Asked Questions

1. How do I get a Gemini 2.5 API key for free?

Create a regular Gemini API key in Google AI Studio and select a free-tier eligible Gemini 2.5 model in your request. Gemini 2.5 does not require a separate key.

2. Where can I find an existing Gemini API key?

Open Dashboard > API Keys in Google AI Studio. If the key is missing, import the Google Cloud project connected to it.

3. Can I use a Gemini API key in frontend code?

Do not place a permanent key in browser or mobile code because users can extract it. Send Gemini API requests through a protected backend instead.

Our AI & Machine Learning Program Duration and Fees

AI & Machine Learning programs typically range from a few weeks to several months, with fees varying based on program and institution.

Program NameDurationFees
Microsoft AI Engineer Program

Cohort Starts: 24 Aug, 2026

24 weeks$2,199
Applied Generative AI and Agentic AI Specialization

Cohort Starts: 27 Aug, 2026

12 weeks$3,390
Professional Certificate in AI and Machine Learning

Cohort Starts: 28 Aug, 2026

24 weeks$4,300
Applied Generative AI Specialization

Cohort Starts: 31 Aug, 2026

16 weeks$2,995
Oxford Programme inStrategic Analysis and Decision Making with AI

Cohort Starts: 3 Sep, 2026

12 weeks$3,390