Skip to main content

Google Gemini API Key: Free Setup Guide (2026)

Get a free Google Gemini API key in Google AI Studio: step-by-step setup, safe key storage, 2026 auth-key migration, and a working server test.

FHFinn Hillebrandt
AI Technology
Google Gemini API Key: Free Setup Guide (2026)
Links marked with * are affiliate links. If a purchase is made through such links, we receive a commission.

Want to use Gemini in your own application, automation, or server-side workflow?

You need a Google Gemini API key. The setup starts in Google AI Studio. The important part comes after that. Treat the key as a password, not as a code snippet to copy around.

This guide covers the current flow for new auth keys, the safe handling of existing standard keys, and a minimal server-side test.

TL;DRKey Takeaways
  • Create an API key: Google AI Studio > Dashboard > API Keys > Create API key > select a project
  • New AI Studio keys are auth keys. Store them only as a server-side environment variable, never in frontend code or a repository
  • New accounts start on the free tier. Check model limits and current prices before production use

1. Prepare your Google account and project

You need a Google account to use the Gemini API. According to Google’s API key guide, AI Studio automatically creates a default project and API key once new users accept the terms.

If you already use Google Cloud, AI Studio does not automatically show every project. Open the project overview in the dashboard, import the project you need, then create a key from the API Keys page.

2. Create a Gemini API key in AI Studio

Open Google AI Studio. In the dashboard, select API Keys, then Create API key.

The overview below shows the Test project with no API keys.

Empty Google AI Studio API Keys overview filtered to the Test example project

In the Create a new key dialog, name the key clearly and select an imported project. Create a new project only when it genuinely needs to be separated from your existing environments.

Google AI Studio dialog for creating a Gemini API key in an existing Cloud project

Check the name and project, then select Create key. After the key is created, copy it and store it only on the server.

3. Store the key safely on the server

Use the key only on the server. For a local test, set it as an environment variable in the current terminal session.

bash
export GEMINI_API_KEY="YOUR_API_KEY"

The official client libraries read the key automatically from GEMINI_API_KEY or GOOGLE_API_KEY. If both are set, Google says GOOGLE_API_KEY takes precedence. If a request runs with an unexpected key, check that second variable first.

For a website or app, the request belongs in a backend. The browser should call only your own endpoint. In production, store the key in the hosting provider’s secret manager.

4. Secure existing keys or replace them with an auth key

The official Google documentation says the Gemini API rejects requests from unrestricted standard keys. Standard keys with explicit restrictions continue to work. Since May 28, 2026, Google AI Studio has created all new API keys as auth keys. Since May 7, 2026, the Gemini API has also blocked unrestricted keys that have been dormant for an extended period.

For an older project or a key of unclear origin, use the safe migration path. Create a new auth key in AI Studio, update the environment variable and deployment configuration, test the request, then revoke the old key only after a successful test.

An older Gemini-only key marked “Unrestricted” can be secured directly in AI Studio. Hover over the label, select Add restrictions, then Restrict to Gemini API only, and confirm with Restrict key. That limits the key’s scope, but does not change its type or replace an auth-key migration.

For IP addresses, websites, or applications, open the key details in the Google Cloud Console. Do not share a Gemini key with other Google APIs. Create a separate key for them, because additional API restrictions can stop Gemini requests from working with that key.

5. Check costs, limits, and billing

New accounts start on the free tier. Available models, rate limits, and prices change by model and tier. The binding values are on the Google pricing page. For a cross-model comparison, use the LLM Price Index.

To access higher limits or paid models, you link a billing account and prepay credits. According to Google's billing page, the minimum purchase is $5 (or the equivalent in other currencies). You can start from the API keys page, the Projects page, or any Set up billing button in AI Studio.

For longer projects, factor in announced price changes. For Gemini 3.8 Flash, Google lists an input price of $0.75 per million tokens through December 31, 2026 and $1.50 starting January 1, 2027.

Monitor usage in AI Studio under Dashboard > Usage. Add Google Cloud billing alerts before a project goes into production.

6. Test the API from the server

The following command follows the current REST reference. It uses the environment variable from the previous step and the active gemini-3.8-flash model. Replace the model name only with a model available to your project and tier.

bash
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 machine learning in one sentence."
  }'

A successful response confirms that the key, project, and model access line up. If the Create API key button is unavailable, an imported project usually lacks IAM permissions. If an older key is blocked, create a new auth key and revoke the old key only after a successful test.

7. What do the Gemini models cost through the API?

The key is free, usage beyond a certain volume is not. Which Gemini model you call decides whether 1 million tokens cost you cents or dollars.

Among the 9 current Google language models with an API price, Gemma 4 31B ($0.21), Gemini 3.5 Flash-Lite ($0.85) and Gemini 3 Flash Preview ($1.13) are the cheapest. All values are blended prices per 1M tokens of three parts input to one part output, as in the LLM price index.

Google's cheapest current model is Gemma 4 31B at rank 12 of 106 ($0.21). The median of all 106 priced language models is $1.53.

API prices

Blended price in US dollars per 1M tokens, 3 parts input to 1 part output

Gemma 4 31B0.21  $
Gemini 3.5 Flash-Lite0.85  $
Gemini 3 Flash Preview1.13  $
Gemini 3.6 Flash1.50  $
Gemini 3.8 Flash1.50  $
Gemini 4 Argon4.00  $
Gemini 4 Carbon4.00  $
Gemini 3.1 Pro Preview4.50  $
Gemini 4 Neon6.00  $

Source: gradually.ai LLM price index

8. How fast do the Gemini models respond?

For chatbots and apps, response time matters as much as price. Here you can see how fast the Gemini models output text.

Among the 8 current Google models OpenRouter measures, Gemini 3.5 Flash-Lite (141 tokens/s), Gemini 3.6 Flash (120 tokens/s) and Gemini 3.1 Pro Preview (104 tokens/s) are the fastest.

Google's fastest current model is Gemini 3.5 Flash-Lite at rank 5 of 100 (141 tokens/s). The median of all 100 measured models is 72 tokens/s of output.

Speed

Gemini 3.5 Flash-Lite141tokens/s · Median across providers on OpenRouter from the readings of the last 24 hours (each covering the last 30 minutes), excluding time to first token · Retrieved 2026-11-23
Gemini 3.6 Flash120tokens/s · Median across providers on OpenRouter from the readings of the last 24 hours (each covering the last 30 minutes), excluding time to first token · Retrieved 2026-11-23
Gemini 3.1 Pro Preview104tokens/s · Median across providers on OpenRouter from the readings of the last 24 hours (each covering the last 30 minutes), excluding time to first token · Retrieved 2026-11-23
Gemini 3 Flash Preview94tokens/s · Median across providers on OpenRouter from the readings of the last 24 hours (each covering the last 30 minutes), excluding time to first token · Retrieved 2026-11-23
Gemini 3.8 Flash75tokens/s · Median across providers on OpenRouter from the readings of the last 24 hours (each covering the last 30 minutes), excluding time to first token · Retrieved 2026-11-23
Gemma 4 31B57tokens/s · Median across providers on OpenRouter from the readings of the last 24 hours (each covering the last 30 minutes), excluding time to first token · Retrieved 2026-11-23
Gemini 4 Argon39tokens/s · Median across providers on OpenRouter from the readings of the last 24 hours (each covering the last 30 minutes), excluding time to first token · Retrieved 2026-11-23
Gemini 4 Carbon38tokens/s · Median across providers on OpenRouter from the readings of the last 24 hours (each covering the last 30 minutes), excluding time to first token · Retrieved 2026-11-23

Output tokens per second, measured by OpenRouter

Frequently Asked Questions about the Google Gemini API

In Google AI Studio, open API Keys, choose Create API key, and select a Cloud project. The key itself is free to create; API use is free only for selected models within their free-tier limits. Check the current pricing page before choosing a model. Store the key on a server, never in frontend code or a public repository.

Partly. Google offers free input and output tokens for selected models, with limited model access and rate limits. Other models and higher-volume production use may require a paid tier.

Current rates are on the Google pricing page, and our LLM Price Index compares them with other providers.

Yes. Every Gemini API key belongs to a Google Cloud project. After a new user accepts the terms, Google AI Studio creates a default project and key. If you already use Google Cloud, import the project you want to use into AI Studio first.

Since May 28, 2026, Google AI Studio creates new keys as auth keys. They are bound to a service account and restricted to the Gemini API by default. Standard keys with no restrictions are rejected, while standard keys with explicit restrictions continue to work.

You can migrate an older standard key by creating an auth key, updating and testing your application, then revoking the old key. Google’s key guide explains the steps. It names no fixed replacement deadline for restricted standard keys.

No. Never put an API key in browser code, a mobile app, or a public repository. Users can extract keys that ship to a client. Production applications should call Gemini from a server or secure backend proxy.

In AI Studio, select “Add restrictions” for an “Unrestricted” key, then choose “Restrict to Gemini API only”. Google says unrestricted standard keys are rejected, while standard keys with explicit restrictions continue to work. For IP, website, or app restrictions, open the key details in Google Cloud Console. A restriction does not change a standard key into an auth key. Use a separate key for other Google APIs.

Not across the board. At the listed rates, GPT-5.6 Luna costs less per million input and output tokens than Gemini 3.5 Flash-Lite. Google lists Gemini 3.5 Flash-Lite at $0.30 per million input tokens and $2.50 per million output tokens. OpenAI lists GPT-5.6 Luna at $0.20 and $1.20, respectively.

Caching, batch processing, tools, and the input-to-output mix can change the bill. Both official price pages and our LLM Price Index list the current rates.

If AI Studio says you do not have permission to create a key, the project is missing one or more required IAM permissions. Google lists project read access, key creation, enabling the Generative Language API, and permission to create and bind the service account. Ask the project administrator to grant a role containing them, or use a project you administer.
FH

Finn Hillebrandt

AI Expert & Blogger

Finn Hillebrandt is the founder of Gradually AI, an SEO and AI expert. He helps online entrepreneurs simplify and automate their processes and marketing with AI. Finn shares his knowledge here on the blog in 50+ articles as well as through the AI Business Club.

Learn more about Finn and the team, follow Finn on LinkedIn, join his Facebook group for ChatGPT, OpenAI & AI Tools or do like 17,500+ others and subscribe to his AI Newsletter with tips, news and offers about AI tools and online business. Also visit his other blog, Blogmojo, which is about WordPress, blogging and SEO.