Gemini API Key: How to Get One and Keep It Safe

You get a Gemini API key in Google AI Studio: sign in with a Google account, open the API keys page and click Create API key. It's free to create, and new accounts start on a free tier with rate limits.

Treat the key like a password, because anyone who has it can call Gemini on your project's quota and, on a paid project, your bill.

Steps checked against Gemini's own docs in Nov 2026. Menus change, so if a screen looks different, follow the linked docs.

How to get a Gemini API key

  1. Go to Google AI Studio and sign in with your Google account.
  2. Accept the Terms of Service. If you're new to Google Cloud, AI Studio creates a default Google Cloud project and an API key for you at this point.
  3. Open the API keys page and click Create API key. Follow the dialog to pick the project the key belongs to.
  4. Copy the key and save it as an environment variable called GEMINI_API_KEY. The Gemini client libraries read it automatically.

Already use Google Cloud? AI Studio won't create a default project for you. Import an existing project from Dashboard, then Projects, and create the key there.

Every Gemini API key belongs to a Google Cloud project. Since May 28, 2026, new keys made in AI Studio are created as "auth keys", and the Gemini API rejects requests from unrestricted older ("standard") keys.

On the free tier, Google's terms say it uses what you submit and the responses "to provide, improve, and develop Google products and services and machine learning technologies", and human reviewers may read them. On the paid tier it doesn't. So keep client or company data out of free-tier projects (Gemini API terms).

Check a key you already have

Not sure which service a key in your config belongs to, or whether you just pasted one somewhere? Paste it below to see what it is and how to revoke it.

Runs only in your browser. The check happens on this page. What you paste isn't sent anywhere, saved or logged, and the checker never contacts the provider. Want proof? Open your browser's network tab, or turn off Wi-Fi, and paste.

What a Gemini API key looks like

Standard Google API keys start with AIza followed by 35 letters, digits, dashes or underscores, so they're 39 characters long. That's the shape the gitleaks rule set looks for.

Keys created in AI Studio since May 28, 2026 are auth keys, and the ones we've seen start with AQ. followed by about 50 letters, digits, dashes and underscores. Google hasn't published that format, so the checker marks these as "likely".

Every older Google API key uses the AIza prefix, so the format alone can't tell a Gemini key from a Maps or Firebase key. Treat any string from the API keys page as a secret, whatever it looks like.

How to store your Gemini API key safely

  • Keep it in an environment variable (GEMINI_API_KEY or GOOGLE_API_KEY; if both are set, GOOGLE_API_KEY wins). Google's docs say to pass the key in code only if you can't use environment variables.
  • Never commit it to Git, and never put it in website or mobile app code. Anyone can read a key from a browser. Call Gemini from your own backend instead.
  • Restrict the key. On the API keys page, click "Add restrictions" on a key marked Unrestricted, then "Restrict to Gemini API only".
  • For production, keep it in Google Cloud Secret Manager and set billing alerts so a stolen key shows up as a spike you notice.

Never paste your Gemini API key into an AI chat

It usually happens while debugging. The error sits next to a config file, you paste the whole thing into ChatGPT or Claude, and the key goes in with everything else.

Once it's sent, the key is stored on someone else's servers, in the chat history, and possibly in training data, depending on your account settings. Deleting the chat doesn't take it back, so treat any key you pasted as exposed and rotate it.

We wrote a step-by-step guide for that moment: what to do in the first hour after pasting an API key into ChatGPT. And if a tool you installed might have read your keys, see how to check whether your AI keys were exposed.

What to do if your Gemini API key leaks

Rotate first and investigate second. A key that no longer works can't be misused.

  1. Create a new key in AI Studio or the Google Cloud console.
  2. Update your app to use the new key and confirm it works.
  3. Disable or delete the exposed key in the Google Cloud console. Google says not to delete the old key until the new one is fully active.
  4. Check billing and usage for requests you didn't make since the key was exposed.

Google says it stops usage of leaked keys its systems detect. That's a useful safety net, and you should still rotate the key yourself.

How Sequirly catches keys at the paste

We build Sequirly, a browser extension that checks what you're about to send to ChatGPT, Claude, Gemini and other AI tools. When a prompt contains an API key, a password or other sensitive data, Sequirly warns you before it leaves your browser, so you can remove it and send the rest.

Sequirly holds an API key before it reaches ChatGPT, then flags customer data in the next prompt.

The check runs inside your browser, and Sequirly says it never sees, stores or sends the values it finds.

There's plenty it doesn't do, so you know where the gaps are:

  • It doesn't scan your code, repos or servers. Use a secret scanner such as gitleaks for that.
  • It doesn't revoke keys or check whether a key is live. Rotation is still on you.
  • It only knows keys by their shape, so a key with no prefix (like Mistral's) can slip past it, just as it slips past the checker above.
  • It warns before it blocks, so a person can still choose to send.

Curious how to test that claim yourself? Our post on whether Sequirly is safe to install walks through a network test you can run.

Common Questions

Is the Gemini API key free?

Yes. Creating a Gemini API key in Google AI Studio is free, and new accounts start on a free tier with rate limits. You only pay if you move the project to a paid tier.

Where do I find my Gemini API key?

Your Gemini API keys are listed on the API keys page in Google AI Studio (aistudio.google.com/api-keys), next to the Google Cloud project each one belongs to.

Does Google train on what I send with a free Gemini API key?

On the free tier, Google's terms say it may use your prompts and responses to improve its products, and human reviewers may read them. On the paid tier, Google says it doesn't.

What does a Gemini API key look like?

New Gemini API keys (auth keys) start with AQ. followed by about 50 characters. Older standard Google API keys start with AIza and are 39 characters long.

Can I put my Gemini API key in front-end JavaScript?

No. Google's docs say not to hardcode keys in web or mobile apps, because anyone can read them. Send requests through your own backend.

Sources

Guides for other API keys

Catch the key before it leaves

If you'd like a warning the next time a key ends up in a prompt, try Sequirly now. Or if you'd rather talk it through with us first, book a quick demo.