Get a key from Google, step by step
- Open Google AI Studio at aistudio.google.com/apikey and sign in with a Google account.
- Click Create API key. Every key belongs to a Google Cloud project. New users get a default project made for them; if you already use Google Cloud, pick or create a project.
- Copy the key and keep it somewhere safe. Since May 28, 2026, new keys are auth keys: tied to a service account and restricted to the Gemini API from the start.
- Set it as an environment variable. Google's SDKs read
GEMINI_API_KEYorGOOGLE_API_KEY; if both are set,GOOGLE_API_KEYwins.
Have an older key? The Gemini API rejects unrestricted standard keys. In AI Studio, hover the key's Unrestricted label, choose Add restrictions and restrict it to the Gemini API.
Test the key
Gemini answers OpenAI-style requests too, which makes for a short test. Native requests send the key in an x-goog-api-key header instead.
export GEMINI_API_KEY="your-key"curl https://generativelanguage.googleapis.com/v1beta/openai/chat/completions \ -H "Authorization: Bearer $GEMINI_API_KEY" \ -H "Content-Type: application/json" \ -d '{"model": "gemini-3.8-flash", "messages": [{"role": "user", "content": "Say hello"}]}'The free tier, and what it costs you
A new key runs on the free tier with no card. It covers the Flash and Flash-Lite models, Gemini 2.5 Pro, the text-to-speech and Live models and embeddings, with lower rate limits than the paid tiers. Gemini 4 Argon, Gemini 3.1 Pro and the image models need billing.
The trade: on the free tier Google uses what you send and what comes back to improve its products, and human reviewers may read it. On the paid tier it doesn't. Keep personal and confidential data off a free key.
Turn on billing
In AI Studio, choose Set up billing on the project, link a Cloud billing account and prepay at least $5. Spend caps rise with what you've paid:
| Tier | To qualify | Spend cap |
|---|---|---|
| Free | An active project | Free models only |
| Tier 1 | A linked billing account | $250 |
| Tier 2 | $100 paid, 3 days after the first payment | $2,000 |
| Tier 3 | $1,000 paid, 30 days after | $20,000 and up |
Then each request is billed per token. List prices per 1M tokens:
| Model | Input | Output | On Zurelay (in / out) |
|---|---|---|---|
| Gemini 4 Argon | $2.00 | $10.00 | $0.80 / $4.00 |
| Gemini 3.1 Pro | $2.00 | $12.00 | $0.80 / $4.80 |
| Gemini 3.8 Flash | $0.75 | $3.75 | $0.32 / $1.59 |
| Gemini 3.5 Flash-Lite | $0.30 | $2.50 | $0.12 / $1.04 |
Does Google AI Pro or Ultra include the API?
No. A Google AI plan's benefits apply inside the AI Studio website only; calling the Gemini API with a key is billed separately, through Google Cloud.
Keep the key safe
- Keep it on the server. A key in a web page or app can be copied and spent on your billing account.
- Restrict every key to the Gemini API, and use a separate project per app.
- Set a budget alert in Google Cloud billing, since paid usage is billed to your account.
Another way: Gemini on the same key as Claude and GPT
On Zurelay, Gemini is one more model name on an OpenAI-compatible key, billed from prepaid credit with no Cloud billing account (58% below Google's list on Gemini 3.8 Flash):
from openai import OpenAIclient = OpenAI(base_url="https://api.zurelay.com/v1", api_key="YOUR_ZURELAY_KEY")reply = client.chat.completions.create( model="gemini-3.8-flash", messages=[{"role": "user", "content": "Say hello"}],)print(reply.choices[0].message.content)There's no free tier on Zurelay; credit starts at $10. If the free tier covers what you need, Google's own key is the cheaper start. See Gemini API pricing for every model.
Steps, free tier and billing read from Google's API key, pricing, rate limits, terms and Google AI plans pages on October 28, 2026.