How to Get a Gemini API Key: Setup, Permissions and Errors
Create or select a Google Cloud project in Google AI Studio, then create a Gemini API key for that project. The key authenticates requests; it does not make every model free or remove the project's quota. This guide covers the new-versus-existing account flow, authorization keys, a minimal request, and the errors that can prevent a valid-looking key from working. Documentation checked October 4, 2026.
October 4 update: clarified Cloud-project setup and authorization-key permissions, removed quota figures supported only by search snippets, and added current billing and error references. The instructions below come from official documentation; they are not a claim that we created a new account or tested your account's eligibility.
Create a Gemini API key in the right Cloud project
Start at the AI Studio API Keys page. A key always belongs to a Google Cloud project, even when you manage it entirely through AI Studio. That project holds the permissions, billing association and quota.
- Sign in and check the project. Google's key documentation says new users receive a default project and key after accepting the service terms. Existing Cloud users may instead need to import a project.
- Import an existing project if necessary. Open Dashboard → Projects, choose Import projects, select the project you intend to use, and return to API Keys. An empty AI Studio project list does not mean your Cloud projects disappeared.
- Create the key in that project. If the action is unavailable, check permissions rather than switching projects at random. An organization policy or missing service-account permissions can block creation.
- Store the key outside your code. Use an environment variable or secret store, and record the project name privately so later billing and quota checks use the same project.
The old shorthand "no Cloud project needed" was misleading. You may not need to open Cloud Console for the normal flow, but a project still exists. On a shared organization project, ask the administrator for the documented permissions; do not bypass the organization's controls to make the button work.
New auth keys are not the same as unrestricted standard keys
Google's documentation says keys newly created in AI Studio have been authorization keys by default since May 28, 2026. They are associated with a service-account identity and restricted to the Generative Language API by default.
Older unrestricted standard keys are rejected by the Gemini API under the current policy. A key string existing in your settings is therefore not proof it remains usable. Check its type and status in AI Studio, and follow Google's migration instructions when an older key needs replacement.
Key creation now also involves linked service-account permissions. If an organization administrator is troubleshooting the disabled button, point them to the official permission list rather than prescribing broad project access as the only solution.
Make one small verification request
On macOS or Linux, set the environment variable in the shell used to run your application:
export GEMINI_API_KEY="YOUR_GEMINI_KEY"
With the current google-genai Python package, Google's quickstart uses the Interactions API. A minimal example adapted for a short response is:
from google import genai
client = genai.Client()
interaction = client.interactions.create(
model="gemini-3.8-flash",
input="Reply with the single word ready."
)
print(interaction.output_text)
Check the model's availability and billing tier before running it. This is a documentation-based example, not a recorded successful call for this update. A paid-tier project may incur charges even for a small request.
If both GOOGLE_API_KEY and GEMINI_API_KEY are set, Google's client libraries give GOOGLE_API_KEY precedence. Check which variable your process receives before assuming the key you just created is the one it sends. Do not print either value into logs.
Existing OpenAI SDK applications can instead use Google's compatibility endpoint at https://generativelanguage.googleapis.com/v1beta/openai/, with a Gemini key and a supported Google model ID. Compatibility is not a guarantee that every provider-specific feature behaves identically.
A free API key is not free access to every Gemini model
Creating a key and enabling paid usage are separate actions. Google's pricing page identifies which models and features have a free tier. For example, its current table offers free-tier token usage for Gemini 3.8 Flash, but not Gemini 3.1 Pro Preview API usage. Free interactive use in AI Studio is also not the same as free programmatic access to every model.
Check the service's available regions and eligibility requirements. Then open your AI Studio rate-limit dashboard for the model and project you will call. The old article's search-snippet quota numbers have been removed; they were not a reliable current allowance for a reader's account.
Google applies API rate limits per project, not per key. Daily request quotas reset at midnight Pacific time, per the rate-limit documentation. Creating additional keys in the same project does not increase the quota, and paid access does not remove all limits.
Match the error before choosing a fix
The following checks summarize Google's API error reference and troubleshooting guide. These are documented failure categories, not incidents observed on your account.
| What you see | Check first | Useful next step |
|---|---|---|
| Create API key unavailable | Selected project and key/service-account permissions | Ask the project administrator to inspect Google's permission requirements |
| 403 or permission-denied message | Actual key, project access and authentication method | Correct the permission or key restriction; repeated retries will not grant access |
| 402 payment-related error | Billing status and prepaid balance | Inspect billing before resending requests |
| 404 model/resource not found | Exact model ID, API version and supported route | Check the current model documentation, not an old alias list |
| 429 RESOURCE_EXHAUSTED | Model/project quota and current request load | Reduce concurrency; use bounded backoff for transient overload, or wait for quota refresh |
| Key reported leaked or blocked | AI Studio key status and accidental exposure | Replace through the authorized key-management process and investigate usage |
Backoff helps transient failures; it does not repair missing permissions, depleted credits or an exhausted daily allowance. Our 429 troubleshooting guide separates those cases.
Billing setup can include prepayment
When the selected model requires paid API access or your free allowance is insufficient, follow Google's billing setup instructions. The current flow can require linking a billing account and adding prepaid credits; Google documents a $5 minimum for the Prepay setup path. Some eligible accounts have a Postpay option instead.
Inspect the billing account, selected project and offered payment arrangement before completing that flow. It is not simply an API-key change, and we did not enable billing or make a payment for this article. For rates, cache charges and worked spending examples, use the separate Gemini API pricing guide.
Keep the key on the server
Do not embed a Gemini key in browser JavaScript, a public repository or a downloadable mobile app. Use a server-side request layer and an appropriate secret store. Restrict keys to the necessary service and application origin where supported, and monitor usage and billing.
A DataLLM Lab gateway key is a separate credential for a separate billing service. It is not a Gemini key, cannot unlock your Google project, and should not be pasted into AI Studio. If you use a gateway, verify its model ID and route in the gateway catalog.
FAQ
Where do I create a Gemini API key?
Use AI Studio's API Keys page and select the correct Cloud project. Existing Cloud users may need to import a project first.
Is getting a Gemini API key free?
Creating the key is separate from usage billing. Free-tier access applies only to eligible models, accounts and project quotas.
Why is Create API key unavailable?
Check the selected project's documented key-creation and linked service-account permissions with its administrator.
Does another API key give me more quota?
No. Limits apply to the project, not to each key.
DataLLM Lab