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.
- 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.

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.

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.
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.
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
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
Output tokens per second, measured by OpenRouter
Frequently Asked Questions about the Google Gemini API
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.
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.
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.






