Gemini API Key Setup (Journal)
This flow is for Gemini API keys in Google AI Studio.
1. Prerequisites
- A signed-in Google account.
- Your account meets AI Studio access requirements (supported region and age requirements).
- If your region is unsupported, use Gemini through Vertex AI.
2. Create the API key
- Open AI Studio API Keys.
- Select an existing project, or create one and generate a key.
- Save the key securely. Use it only on server side and never commit it to code.
Note: new users are often given a default project and API key automatically.
3. Enable paid tier (if needed)
- Review your current tier in Gemini API Billing docs.
- In AI Studio API keys or project settings, click
Set up billingfor the target project. - After Cloud Billing is connected, that project’s keys use paid-tier billing and quotas.
4. Local environment variable
export GEMINI_API_KEY="your_api_key_here"The Gemini SDK supports both GEMINI_API_KEY and GOOGLE_API_KEY. If both are set, GOOGLE_API_KEY takes precedence.
5. Minimal verification
curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent?key=${GEMINI_API_KEY}" \
-H "Content-Type: application/json" \
-X POST \
-d '{
"contents": [{
"parts": [{
"text": "Return OK"
}]
}]
}'If the response contains model output, the key is working.
6. Common issues (direct cause -> direct fix)
- Symptom: AI Studio redirects to region availability page
- Cause: current account region or eligibility requirements are not met.
- Fix: use an eligible account/region, or switch to Vertex AI.
- Symptom: rate limits are hit quickly even with multiple keys
- Cause: limits are enforced at project level, not per key.
- Fix: review project-level quotas and upgrade tier or split projects if required.
- Symptom: Free Tier works for testing but fails under production load
- Cause: Free Tier has lower quota and stricter limits.
- Fix: move to Paid Tier and monitor project quota usage.