Teams adopt the Gemini API through Google AI Studio in minutes, and the default project, key and free quota they get are easy to carry into production without anyone deciding which data terms, logging settings and spend limits apply. The security of a Gemini integration depends on four customer-side choices: what kind of key you use and where it lives, which Google Cloud project it belongs to, whether that project is on the free or paid tier (which changes how Google may use your prompts), and how logs, uploaded files and spend are controlled. This guide covers those choices for developers, platform engineers and security teams who run the Gemini Developer API (generativelanguage.googleapis.com) from AI Studio or their own code. Key restriction mechanics in general, Cloud Monitoring by credential_id and the Admin Activity audit trail are covered in the Google API Keys Security Guide; this page builds on it for Gemini specifically.
This is an independent guide from NHI Mgmt Group, based on Google's public Gemini API documentation as of November 2026. It is not sponsored or reviewed by Google. Product features change, so confirm settings against Google's current documentation.
Key takeaways
- Billing status sets the data terms. Under the Gemini API Additional Terms, free (Unpaid Services) prompts and responses may be used to improve Google products and read by human reviewers; paid use is not used for product improvement. A project only counts as paid when it is linked to an active Cloud Billing account.
- Use authorization keys, kept on a server. New AI Studio keys have been authorization keys bound to a service account since 28 May 2026, and the API rejects unrestricted standard keys. Never ship any Gemini key in browser or mobile code; use a backend, or ephemeral tokens for the Live API.
- The project is the security boundary. Rate limits, spend caps, uploaded files and AI Studio logs are all scoped to the Google Cloud project, not to the key, so separate projects per environment and per sensitivity level.
- Logs hold full prompts and responses. AI Studio logging is on by default for the Interactions API and for Generate Content in projects created on or after 26 October 2026; set the retention window deliberately and treat datasets, which do not expire, as stored data.
- Cap spend in two places. Set a project monthly spend cap and watch the billing account tier cap; a stolen key is first a billing problem, and with prepay a zero balance stops every key on every linked project.
How Gemini API access is structured
Every Gemini API key belongs to a Google Cloud project, and the project carries billing, collaborators, quota and permissions. New AI Studio users receive a default project and key automatically after accepting the terms; users with an existing Google Cloud account import projects through Dashboard, Projects, Import projects. That convenience is the first governance gap: a default project created by an individual often sits outside the organisation's resource hierarchy, so organisation policies, central billing and audit log sinks do not apply to it.
| Credential | Identity it carries | Where it belongs | Key points from Google's documentation |
|---|---|---|---|
| Authorization (auth) key | The bound service account | Server-side code, stored in a secret manager | Default for new AI Studio keys from 28 May 2026; restricted to the Generative Language API by default; fast-acting leaked key enforcement; requests do not appear in service account usage metrics |
| Standard key with explicit restrictions | The project only (billing and quota) | Legacy server workloads pending migration | Keeps working if restricted; migrate to an auth key |
| Unrestricted standard key | The project only | Nowhere | Requests are rejected; long-dormant unrestricted keys were blocked from 7 May 2026 and show a Blocked tag in AI Studio |
| Ephemeral token (Preview) | Issued by your backend for one client session | Browser or device connecting to the Live API over WebSockets | Defaults: 1 minute to start a session, 30 minutes of use, 1 use; can be locked to a model and configuration |
- Who can create keys: Google lists
apikeys.keys.create,serviceusage.services.enable,iam.serviceAccounts.create,iam.serviceAccountApiKeyBindings.createandresourcemanager.projects.get, and notes that Project Editor typically covers them. That means anyone with Editor on a project can enable the API, create a service account and mint a key. Restrict Editor on AI projects and grant a narrower custom role to the people who issue keys. See the Google Cloud IAM and Service Accounts Guide. - The bound service account: create a dedicated account per application with no roles granted, and never bind a key to a shared or default account.
- Visibility limits: AI Studio shows only unrestricted keys and keys restricted to the Gemini API, and lists up to 100 keys and 50 projects. Inventory from the Cloud console or the API Keys API, not from AI Studio alone. The AI Studio Usage page groups traffic it cannot match under (unknown keys), which includes keys deleted more than 30 days ago and other credentials such as OAuth; unexplained volume there deserves a look.
- Header, not URL: send keys in the
x-goog-api-keyheader. The SDKs readGEMINI_API_KEYorGOOGLE_API_KEYfrom the environment, and if both are setGOOGLE_API_KEYwins. A staleGOOGLE_API_KEYleft on a build agent can silently route calls to the wrong project, so set only one.
Data use terms: free tier versus paid tier
The Gemini API Additional Terms of Service (effective 23 March 2026 at the time of checking) split the service into Unpaid and Paid Services, and the difference is the single most important fact for anyone sending business data.
| Aspect | Unpaid Services (free AI Studio, free API quota) | Paid Services (project linked to active billing) |
|---|---|---|
| Use for product improvement | Inputs and outputs may be used to provide, improve and develop Google products and machine learning | Prompts and responses are not used to improve Google products |
| Human review | Human reviewers may read, annotate and process input and output, after it is disconnected from your account, key and project | Flagged content may be reviewed by authorised Google staff for policy enforcement |
| Google's own advice | Do not submit sensitive, confidential or personal information | Processing under the Data Processing Addendum |
| Abuse monitoring logs | Prompts, context and responses kept for 55 days for detecting Prohibited Use Policy violations, safety and security, and legal disclosures (usage policies page) | |
| Grounding with Google Search or Maps | Prompts, context and output stored for 30 days, may be used for debugging and testing | |
- What makes a project paid: the API is paid only through a Cloud project associated with an active billing account. AI Studio use counts as paid if the account has a Cloud project with active Cloud Billing, or is a Workspace enterprise account. Check for projects marked Paid on the AI Studio API keys page rather than assuming.
- Regional rule: the terms apply Paid Services data use to the EEA, Switzerland and the UK even for free use, and say only Paid Services may be used when making API clients available to users there.
- Age: users must be 18 or older, which matters for consumer-facing products built on the API.
- Opting data back in: sharing logs as a dataset, or sending thumbs up or down feedback, puts that data under the Unpaid Services terms, including possible use for training and human review. The invite-only Contributor Tier exchanges token discounts for data use on select models. Treat any of these as a data sharing decision that needs the same approval as any other disclosure.
Practical consequence: a developer prototyping with production data on a personal free project has, under these terms, offered that data for product improvement. Policy should say that only approved, billing-linked projects inside the organisation may receive non-public data, and an acceptable use policy should say it in plain words. See the AI Acceptable Use Policy Template.
Logs, datasets and uploaded files
Two features store your content inside the project for longer than a single request, and both should be configured on purpose.
| Store | What it holds | Default | Controls |
|---|---|---|---|
| AI Studio logs | Full prompt, response and prior-turn context for Generate Content, Batch, Stream and Interactions calls (including OpenAI-compatible endpoints) | Paid projects only; on for Interactions; on for Generate Content in projects created on or after 26 October 2026; 55-day retention | Per-API toggle in the Logs Settings panel (project owner); retention 7, 14, 28 or 55 days; request-level store setting overrides the project |
| Datasets | Logs you select and save, exportable as CSV, JSONL or to Google Sheets | No expiry | Delete when the evaluation ends; opt out of sharing with Google when creating |
| Files API | Media and documents uploaded for prompts | Deleted after 48 hours; up to 20 GB per project, 2 GB per file | Delete explicitly after use; user uploads cannot be downloaded back, model-generated files can |
- Logs are a data store: if your prompts contain customer records, the logs now hold them for up to 55 days. Choose the shortest retention that still supports debugging, set
storeto false on requests that carry regulated data, and record the decision in your data inventory. - Turning logs off has side effects: disabling Interactions logging also stops automatic storage and retrieval of conversation history unless a request overrides it, so test multi-turn features after the change.
- Log visibility depends on keys: a project needs at least one active API key for its logs to display, so deleting every key during an incident also hides the logs in AI Studio. Rotate to a new key rather than deleting all of them while you investigate.
- Files sit with the project, not the key: anyone holding a working key for the project can work with the project's files during the retention window. Delete files when a job finishes and keep sensitive workloads in their own project.
Spend, quota and abuse of stolen keys
A leaked Gemini key is used first to run inference at the owner's expense, which ATT&CK describes as T1496.004 Cloud Service Hijacking, and OWASP lists as LLM10:2025 Unbounded Consumption. Keys usually leak through source files and configuration (T1552.001 Credentials In Files).
| Control | Scope | Behaviour | Use it for |
|---|---|---|---|
| Project monthly spend cap (experimental) | Project | Set on the Spend page; overage possible during roughly 10 minutes of billing latency | A hard ceiling per application or environment |
| Billing tier cap | Billing account | Tier 1 $250, Tier 2 $2,000, Tier 3 $20,000 to $100,000+; when reached, service pauses for all linked projects until the 1st of next month | Understanding the worst case across every project on the account |
| Spend-based rate limit | Billing tier, rolling 10 minutes | Tier 1 $10, Tier 2 $50, Tier 3 $200 per 10 minutes; HTTP 429 RESOURCE_EXHAUSTED | Slowing a burst from a stolen key |
| Prepay credits | Billing account | At $0 balance, all keys in all linked projects fail with HTTP 402; auto-reload with a monthly auto-charge limit | Bounding cost, at the price of a shared outage |
| RPM, TPM and RPD limits | Project, not key | RPD resets at midnight Pacific time | Capacity planning; a noisy test key can starve production in the same project |
Decision guidance: because tier caps and prepay balances are shared across a billing account, one compromised project can pause or drain every Gemini workload on that account. Large organisations should give production its own billing account or at least its own project with a spend cap set below the tier cap; small teams on one billing account should set project caps on every project and auto-reload limits on prepay. Requests that fail with 400 or 500 errors are not charged but still count against quota. For runaway agent loops as well as theft, see the Denial-of-Wallet and AI Agent Cost Runaway Guide.
Client apps, ephemeral tokens and safety settings
- No keys in clients: Google's key page says not to embed keys in web or mobile apps and to route calls through a backend. Client-side restrictions (referrer, Android, iOS) can be bypassed, so they do not make a Gemini key safe to publish.
- Ephemeral tokens for the Live API: the backend authenticates the user, requests a token and passes it to the client, which connects over WebSockets (
v1beta). Keep the defaults short or shorter:newSessionExpireTime1 minute,expireTime30 minutes,uses1, with reconnection through session resumption every 10 minutes. Lock the token to the model, response modality and configuration so that system instructions stay on the server. Google's own caveat applies: tokens are only as secure as your backend authentication, and they can be extracted from the client like any secret. Do not use them for server-to-Gemini calls. - Safety settings are your choice: the documented harm categories are
harassment,hate_speech,sexually_explicit,dangerous_contentandjailbreak, with thresholdsoff,block_only_high,block_medium_and_aboveandblock_low_and_above. Unset categories default to Off for Gemini 2.5 and later models, so a user-facing product should set thresholds explicitly. Blocked interactions fail with HTTP 400 and codes such assafety,jailbreak,prohibited_contentorblocklist; log those codes, they are a useful abuse signal. Core protections such as child safety cannot be turned off. - Safety filters are not injection defences: the
jailbreakcategory helps, but content fetched through grounding, URL context or uploaded files can still carry indirect instructions. Keep tool permissions narrow and validate outputs before they drive actions. See the Prompt Injection Guide.
Where identity fits
An authorization key is a non-human identity credential: a long-lived bearer secret that acts as a service account. Manage it like any other machine credential. Give each application its own service account and key, record an owner, store the key in Secret Manager (or your secrets platform) and inject it at runtime, and rotate it on a schedule and on staff changes. Keep the organisation policy constraint constraints/iam.managed.disableServiceAccountApiKeyCreation enforced; the Google API Keys Security Guide explains its Gemini exception. For workloads already running on Google Cloud, prefer short-lived credentials from the attached service account where the client library supports it. See the Secrets Management Guide.
Rolling out a governed Gemini estate
- Inventory: list every project with the Generative Language API enabled and every key in them from the Cloud console, including personal projects that developers have used for work. Record key type (Standard or auth), restrictions, bound service account, owner and billing status.
- Bring projects inside the organisation: move or recreate work projects under a dedicated AI folder so organisation policy, central billing and audit log sinks apply. Retire personal default projects for work use. See the Google Cloud Organization Policy Guide.
- Decide the tier per project: link every project that will see non-public data to an approved billing account so Paid Services terms apply, and confirm the Paid marker in AI Studio.
- Migrate keys: create a new auth key per application, update environment variables and deployment configuration, test, then disable the old Standard key. Keep it disabled, not deleted, for a short observation window so you can restore service if something breaks; Google's leaked key procedure follows the same create, deploy, disable order.
- Set limits: project spend caps on every project, prepay auto-charge limits, and alerts on the billing account.
- Configure storage: choose log retention per project, decide which request paths set
storeto false, and schedule deletion of datasets and uploaded files. - Pilot, then enforce: run one application through the new pattern for two weeks, review logs, cost and error codes, then make the pattern a platform default and block new keys outside the approved folder.
Detection and measurement
- Admin changes: Cloud Audit Logs Admin Activity entries for
apikeys.googleapis.com(key created, restrictions changed) and for service usage (Generative Language API enabled in a new project). Route them to your SIEM through an aggregated sink. See the Google Cloud Audit Logs and Log Sinks Guide. - Usage anomalies: per-key traffic in the AI Studio Usage page and Cloud Monitoring, sudden growth in (unknown keys), requests outside working hours, and new models appearing for an existing application.
- Error codes: spikes in HTTP 429, 402 or safety block codes often mean abuse or a runaway loop.
- Leaks: secret scanning in repositories and CI for keys beginning
AIza, with a triage path that rotates first. See the Git Secret Scanning Guide.
Metrics: percentage of Gemini keys that are auth keys (target 100%); projects with the API enabled that sit outside the organisation (target 0); projects receiving non-public data that are not Paid (target 0); projects without a spend cap; median time from leak alert to key disabled; datasets older than their approved review date.
Common failure patterns
- Prototype becomes production: the default AI Studio project and key created by one developer end up serving a live feature, with no owner, no organisation policy and free tier data terms.
- Free tier with real data: customer documents pasted into free AI Studio prompts, which the terms allow Google to use for improvement and human review.
- Keys in the front end: a Gemini key embedded in a single page app or mobile build "because it is restricted to the referrer", which can be bypassed.
- Shared project for test and production: a load test exhausts project-level RPD, or a leaked test key reaches production files and logs because both live in one project.
- Datasets forgotten: logs saved to datasets for an evaluation have no expiry and outlive the data retention promise made to customers.
- Deleting every key during an incident: service stops and the AI Studio logs disappear from view just when they are needed; disable and replace instead.
Framework mapping
| Control area | NIST SP 800-53 Rev 5 | NIST CSF 2.0 | Other |
|---|---|---|---|
| Key lifecycle, storage and rotation | IA-5 Authenticator Management | PR.AA-05 | ATT&CK T1552.001, T1528 |
| Who can create keys and enable APIs | AC-6 Least Privilege | PR.AA-05 | ISO/IEC 27001:2022 A.5.15 Access control |
| Logs, datasets and file retention | AU-6 | PR.DS-01 | OWASP LLM02:2025 Sensitive Information Disclosure |
| Spend caps and usage monitoring | SI-4 System Monitoring | DE.CM-09 | ATT&CK T1496.004; OWASP LLM10:2025 Unbounded Consumption |
| Data use terms and tier decisions | SA-9 External System Services | GV.SC-05 | ISO/IEC 27001:2022 A.5.19 supplier relationships |
Practitioner checklist
- Inventory every project with the Generative Language API enabled, from the Cloud console, including personal projects used for work.
- Keep all work projects inside the organisation and link those handling non-public data to an approved billing account, then confirm they show as Paid.
- Replace every Standard key with a per-application authorization key bound to a dedicated service account with no IAM roles.
- Store keys in a secret manager, set only one of
GEMINI_API_KEYorGOOGLE_API_KEY, and send keys in thex-goog-api-keyheader. - Never ship a key to a client; use a backend proxy or short, locked ephemeral tokens for the Live API.
- Set a project monthly spend cap on every project and limit prepay auto-reload.
- Choose log retention deliberately, set
storeto false for regulated requests, and delete datasets and uploaded files when done. - Set safety thresholds explicitly for user-facing products and log block codes.
- Require approval before sharing logs, datasets or feedback with Google, since shared data falls under Unpaid Services terms.
- Alert on key creation, restriction changes and new API enablement, and rehearse the create, deploy, disable leak procedure.
Standards and references
- Google: Gemini API Additional Terms of Service
- Google: Using Gemini API keys
- Google: Gemini API billing
- Google: Gemini API rate limits
- Google: Data logging and sharing policy
- Google: Ephemeral tokens
- Google: Gemini API usage policies and abuse monitoring
- OWASP: Top 10 for LLM Applications 2025
Related NHI Mgmt Group resources: Google API Keys Security Guide · Google Cloud Service Account Keys Security Guide · Google Cloud IAM and Service Accounts Guide · LLM Security Guide · Secrets Management Guide