Gemini API keys

How to get a Gemini API key

New users who sign in at aistudio.google.com/apikey and accept the terms get a default Google Cloud project and a free-tier Gemini API key. Since May 28, 2026 every new key created in AI Studio is an authorization key, and rate limits count per project, not per key.

Where to create it
aistudio.google.com/apikey
Cost to start
Free tier, no billing
New keys since May 2026
Authorization keys
Rate limits
Per project, not per key

Updated

Create a Gemini API key in 5 steps

  1. Open https://aistudio.google.com/apikey in your browser and sign in with your Google account.
  2. Accept the Terms of Service. If you're a new user, Google AI Studio sets up a default Google Cloud project and creates a free Gemini API key right away.
  3. If you already use Google Cloud, you don't get a default project, so import one first: open the Projects view in AI Studio, pick Import projects, search for and select your project, and click Import.
  4. Go to the API Keys page to copy your existing key or create a new Gemini API key for the imported project.
  5. Save the key in your environment as GEMINI_API_KEY. Google's SDKs look for both GEMINI_API_KEY and GOOGLE_API_KEY automatically, and GOOGLE_API_KEY wins if both variables are set.

If the Create API key button is greyed out with "You do not have permission to create a key in this project", ask an admin for the Project Editor role (which bundles resourcemanager.projects.get, apikeys.keys.create, serviceusage.services.enable, iam.serviceAccounts.create, and iam.serviceAccountApiKeyBindings.create), or create a new Cloud project that isn't attached to an organization.

Make your first call

Send the key in the x-goog-api-key header, like in the curl example below that posts to https://generativelanguage.googleapis.com/v1beta/interactions using gemini-3.8-flash. That same key also works with Google's OpenAI compatibility layer if you point your client at the base URL https://generativelanguage.googleapis.com/v1beta/openai/.

curl
curl "https://generativelanguage.googleapis.com/v1beta/interactions" \
  -H "Content-Type: application/json" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -X POST \
  -d '{"model": "gemini-3.8-flash", "input": "Explain how AI works in a few words"}'

Authorization keys vs standard keys

Starting May 28, 2026, Google AI Studio only creates authorization keys. Each authorization key is bound to a service account, comes restricted to the Generative Language API by default, and gets faster leaked-key enforcement.

The Gemini API now rejects requests from unrestricted standard keys, though older standard keys with explicit API restrictions that include the Gemini API keep working. If you're still on an unrestricted standard key, you'll need to restrict it or swap it out using Google's 7-step migration guide, which ends with revoking the old key.

The table below shows which key types the Gemini API accepts.

Since May 7, 2026, unrestricted keys that sit dormant for an extended period get blocked by the Gemini API and show a Blocked tag in AI Studio, so you'll have to generate a new key or switch to an existing restricted one.

Gemini API key types
Key typeHow it worksAccepted by the Gemini API
Authorization keyBound to a service account, limited to the Generative Language APIYes, the default for new keys since May 28, 2026
Standard key with API restrictionsExplicit API restrictions that include the Gemini APIYes
Standard key without restrictionsUsable with any enabled APINo, requests are rejected

Free vs paid keys

A key's tier comes from the Google Cloud project it belongs to: a project with no linked billing account is on the free tier, while a project linked to a Cloud Billing account inherits that account's usage tier. The table below breaks down what changes when you move a project from free to paid.

  • Upgrading a project to the paid tier means linking a Cloud Billing account; new users default to Prepay and buy at least $5 of credits, while some eligible accounts can choose or are assigned Postpay instead.
  • With Prepay billing, hitting a $0 credit balance stops every API key on that billing account and your requests return HTTP 402.

See the Gemini API pricing breakdown for all per-model token prices.

Gemini API free tier vs paid tier
ItemFree tierPaid tier
Token costNo charge on models with a free tierBilled per 1M tokens
Gemini 4 ArgonNot available$2.00 in, $10.00 out per 1M
Gemini 3.8 FlashFree of charge$0.75 in, $3.75 out per 1M
Batch APINot on most models; free on 3.5 and 3.1 Flash-Lite50% below Standard prices
Rate limitsFree tier limitsHigher, rising by usage tier
Your prompts and responsesUsed to improve Google productsNot used to improve products (except the invite-only Contributor tier)

Restrict and protect your key

  • Never commit your key to source control.
  • Never ship a key in client-side browser or mobile code; call the Gemini API from your own backend instead.
  • Store keys in environment variables or a secret manager like Google Cloud Secret Manager.
  • Restrict the key to the Gemini API in AI Studio (which requires the apikeys.keys.update permission) or set application restrictions such as allowed IP addresses on the Credentials page of the Google Cloud console.
  • Use a separate key for other Google services, because a key restricted to those services cannot call the Gemini API.
  • Set billing alerts on your Google Cloud account so unexpected usage doesn't catch you off guard.

If a key leaks, create a new key, update and deploy your apps with it, disable or delete the compromised key, and then audit your usage and billing.

Quotas in brief

Rate limits are measured in requests per minute (RPM), input tokens per minute (TPM), and requests per day (RPD). Because limits apply per Google Cloud project rather than per key, creating extra keys in the same project adds no quota at all.

RPD resets at midnight Pacific time. Google doesn't publish fixed per-model limits and notes that specified limits aren't guaranteed, so check AI Studio to see your project's active limits, or read our free tier guide for what's included at $0.

Paid projects move up usage tiers automatically: Tier 1 when you link an active billing account, Tier 2 after $100 paid and 3 days since your first successful payment, and Tier 3 after $1,000 paid and 30 days.

Use a Google AI Pro or Ultra plan as an API

If you already pay for a Google AI Pro or Ultra subscription, Plan2API connects that Google account through Antigravity and gives you a p2a_ key for an OpenAI-compatible Chat Completions endpoint (POST /v1/chat/completions) at https://api.plan2api.com/v1. You can call models like gemini/gemini-4-argon-high and gemini/gemini-3.8-flash-high with a Bearer token in the Authorization header. Requests count against your Google plan's own usage limits, and Plan2API never bills per token.

The Plan2API Free plan costs $0 with no card required and gives you 1 connected subscription, 2 API keys, and 50 chat requests a day (resetting at 00:00 UTC). Read how the Gemini subscription API works or connect your Google account to get a key and run the curl call below.

curl
curl https://api.plan2api.com/v1/chat/completions \
  -H "Authorization: Bearer $PLAN2API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "gemini/gemini-4-argon-high", "messages": [{"role": "user", "content": "Explain how AI works in a few words"}]}'

Use the AI subscriptions you already pay for as one OpenAI-compatible API key.

  • Free: 1 subscription, 50 requests a day, no card
  • Pro: $12 a month

FAQ

Is a Gemini API key free?

Yes. Creating a key costs nothing and a project without a linked billing account stays on the free tier, so billing only begins once you link a Cloud Billing account (new users then prepay at least $5 of credits, while some eligible accounts use Postpay). Some models, like Gemini 4 Argon, have no free tier and require a paid project.

Are Gemini API rate limits per key or per project?

Per project. Generating more API keys inside the same Google Cloud project adds no extra quota, and daily request limits (RPD) reset at midnight Pacific time.

Why is the Create API key button greyed out in AI Studio?

Your account is missing project permissions in Google Cloud. Ask an administrator for the Project Editor role, or create a new Google Cloud project that is not part of an organization.

Can I use a Gemini API key with the OpenAI SDK?

Yes. Point the SDK's base URL to https://generativelanguage.googleapis.com/v1beta/openai/ and pass your Gemini key as the API key.

What should I do if my Gemini API key leaks?

Create a new key right away, update and deploy your apps with it, and then disable or delete the leaked key. Once the old key is off, audit your project's usage and billing logs.

Sources

  1. Google: Using Gemini API keysai.google.dev
  2. Google: Gemini API billingai.google.dev
  3. Google: Gemini API rate limitsai.google.dev
  4. Google: Gemini API pricingai.google.dev
  5. Google: OpenAI compatibilityai.google.dev