Gemini API Key: Setup, First Request, Billing, and Cost Controls
Updated October 22, 2026 · first published October 22, 2026
A Gemini API key lets an application call Google's Gemini API, and each key is associated with a Google Cloud project that carries its quota and billing context. Create the key in Google AI Studio, keep it on a server, and check the model's current free eligibility and price before you send traffic. A budget alert alone does not stop usage.
How do I create a Gemini API key?
Open Google AI Studio's API keys page, sign in, and create a key in a project. For a new user, AI Studio can create a default Google Cloud project and key after the terms are accepted. If you already have a Cloud project, import it into AI Studio first, then create the key there. The project is the useful unit to name and govern: it groups collaborators, billing, and API quota.
As of October 2026, AI Studio creates new keys as authorization keys by default. These keys are bound to a service account and restricted to the Gemini API; older standard keys have different security properties, and unrestricted standard keys are rejected. Treat either kind as a secret: keep it out of Git and browser or mobile code. Put it in a server-side environment variable or secret manager. Google's API key guide explains key types, project setup, and restrictions.
How do I send a first request?
Set GEMINI_API_KEY in your shell using the key you created, then try this small text request. It uses the current gemini-3.8-flash model ID and the documented generateContent REST endpoint. The example contains no credential; run it only after you have set your own environment variable.
export GEMINI_API_KEY='YOUR_KEY_FROM_AI_STUDIO'
curl -X POST 'https://generativelanguage.googleapis.com/v1beta/models/gemini-3.8-flash:generateContent' \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H 'Content-Type: application/json' \
-d '{"contents":[{"parts":[{"text":"Give me one sentence explaining an API key."}]}]}'
Keep the key on the server when you build an application for other people. A secret stored in frontend JavaScript can be extracted, and a leaked key can let someone else use the project's quota and billing. Restrict keys where the key type and workload allow it, and rotate a compromised key. For setup details, see Google's getting-started guide and REST text-generation example.
What does Gemini's free tier include?
“Free tier” is not a promise that every Gemini model or feature is free. Google says new accounts begin on the Free Tier, with access to certain models up to each model's free-tier rate limits. Model availability and limits vary; check the current model row on the pricing page and the project's active limits in AI Studio before estimating a workload. Free access can be a useful learning path, but it has usage limits and may have different data-use terms than paid access.
Linking a billing account upgrades a project to a paid tier and unlocks its paid pricing and higher limits. Google's current billing guide says eligible accounts may use prepay and describes a $5 minimum credit purchase when switching to prepay. A paid project can incur charges for API use, so don't infer “free” from the fact that the key was created in AI Studio. Check the project plan and payment setup in the AI Studio Billing view.
How is a Gemini API request billed?
For standard text generation, the main cost inputs are tokens sent to the model and tokens it returns. Model choice, thinking tokens, caching, and optional tools can change the bill. Check the current model and feature prices rather than applying one flat “Gemini price.” In Google's published standard rates for Gemini 3.8 Flash through December 31, 2026, input is $0.75 per million tokens and output, including thinking tokens, is $3.75 per million. The same page lists higher rates beginning January 1, 2027, so refresh estimates when rates change.
Worked illustration: suppose a workload sends 1,000,000 requests in a month, each with 10,000 input tokens and 1,000 output tokens. That is 10 billion input tokens × $0.75 ÷ 1 million = $7,500, plus 1 billion output tokens × $3.75 ÷ 1 million = $3,750, or $11,250 before any separate tools, taxes, credits, or discounts. This is a planning example, not a forecast: actual token counts can vary, and thinking tokens count as output on this model. For comparison, each 1,000 input tokens costs $0.00075 and each 1,000 output tokens costs $0.00375 at those rates.
A retry is another request attempt, so track attempts as well as successful user actions. Google says failed 400 or 500 requests are not charged for tokens, but still count against quota; completed work in some interrupted interactions may be billed. Use bounded retries with backoff for transient errors, avoid retrying invalid or payment errors, and inspect usage rather than assuming every network timeout was free.
Which limits and budgets actually control spend?
Gemini rate limits such as requests per minute, tokens per minute, and requests per day apply per project, not per API key. Creating several keys inside one project therefore does not multiply the project's quota. Those limits mainly control throughput and availability; they are not a team-set monthly budget. The rate-limits page shows current limits and tier qualifications, which vary by model and can change.
For a practical first guardrail, use a dedicated project for each workload or environment that needs its own quota, owner, and spend boundary. In AI Studio's Spend page, eligible accounts can configure a monthly project spend cap. Google labels project caps experimental and says usage can exceed the target during roughly a 10-minute billing-data delay; long-running batch or agent work may also exceed it. Billing-tier caps aggregate usage across linked projects and can pause Gemini API service across those projects when the billing account limit is reached. These are useful platform controls, not guaranteed exact invoice ceilings.
Also set a Cloud Billing budget with alerts at levels that give the owner time to respond, such as 50%, 80%, and 100% of the plan. An alerts-only budget notifies; it does not automatically stop calls. If your service and account support Cloud Billing spend-cap budgets, those can pause covered usage when an estimated threshold is reached, but Google also warns that enforcement is not instant and overage can still be billed. For a full explanation of that separate control, see our Google Cloud AI spend caps guide.
At the application layer, set a maximum output size, bound retries, use the least expensive model that meets your quality target, and track request volume and token counts by feature or customer. Combine those limits with alerts and a named owner who can pause traffic. This makes a cost spike diagnosable and gives you more than a single bill notification as protection.
Which Google docs support this guide?
Documentation and prices checked 22 October 2026. The request example is provided for you to run; no API call was made for this article.
- Google AI for Developers: Using Gemini API keys
- Google AI for Developers: Getting started
- Google AI for Developers: Billing
- Google AI for Developers: Gemini API pricing
- Google AI for Developers: Rate limits
- Google Cloud: Budgets and alerts
- Google Cloud: Manage spend cap budgets
What should I read next?
Related
Want this applied to your stack? Bring the provider bills, gateway logs, and top workflows; we will map the cost drivers and savings path. Book a free audit →