EN
Gmail API authentication

Gmail API Key vs OAuth: Why You Can't Skip OAuth (and What to Use Instead)

There is no Gmail API key. Gmail rejects API keys with a 401 error, "API keys are not supported by this API". To read or send mail, use an OAuth client, a service account with domain-wide delegation, or a unified API. Here is the exact error, how to create the credentials that work, and which path fits your app.

Gmail Gmail API requests
GET/users/me/messages?key=AIza...API keys are not supported by this API401
GET/users/me/messagesAuthorization: Bearer ya29...200
GET https://gmail.googleapis.com/gmail/v1/users/me/messages OAuth only
Short answer

No, you can't use an API key with the Gmail API. Gmail only serves private user data, so every request needs an OAuth 2.0 access token in the Authorization: Bearer header. A request with ?key= returns 401 UNAUTHENTICATED.

Creating an OAuth client is free, and the Gmail API itself is free on Google's Standard Tier: see Gmail API pricing and quotas.

Updated December 2026Error response tested on December 4, 2026

The verdict

Can You Use an API Key with the Gmail API?

No. API keys work for Maps or Translate, so it's natural to try one on Gmail. Google rejects it: no flag, header or setting changes that.

API key: public data only

A key identifies your Google Cloud project, not a user. Gmail never serves public data.

OAuth 2.0: required for Gmail

An access token proves which user consented and which scopes they granted. No token, no mailbox.

Real response of gmail.googleapis.com, tested on December 4, 2026 (abridged). The errors array adds "Login Required."

Concepts

What an API Key Actually Does on Google Cloud (and Doesn't)

Google Cloud offers three kinds of credentials. Each one answers a different question: which project, which user, or which application.

Project credential API key

Anonymous access to public data, metered on your project: Maps, Translate, public YouTube data. Never Gmail.

User credential OAuth 2.0 client ID

Starts a consent flow. The user approves scopes, and Google issues the access token Gmail accepts.

App credential Service account

Acts as your application. Reads a Workspace user's Gmail only through domain-wide delegation set by an admin.

Rule of thumb: if an API touches a user's account (Gmail, Calendar, Drive, Contacts), Google requires that user's OAuth consent or an admin delegation. Source: Google's Create access credentials. Last verified: December 4, 2026.

Architecture

Why Gmail Requires OAuth 2.0

Gmail data belongs to the user, not to your app. OAuth is how Google grants scoped, revocable access to it.

01

User consent

The user sees your app's name and the scopes it requests, and says yes or no.
02

Scoped, revocable access

Read-only, send, or full access. The user can remove your app at any time.
03

Short-lived tokens

Access tokens last about an hour. Your app renews them with a refresh token.
Passwords stopped working on March 14, 2025

The Gmail API never accepted a password. What changed is IMAP, SMTP, POP, CalDAV and CardDAV: Google shut off password sign-in ("less secure apps") for every Google Account on March 14, 2025. Only app passwords still work there. Source: Google's transition guide.

Step by step

How to get a Gmail API key (and what to create instead)

What you need is an OAuth client ID and secret, created in five steps in the Google Cloud console.

  1. Create a Google Cloud project in the Google Cloud console.
  2. Enable the Gmail API in APIs and Services, Library.
  3. Set up Google Auth Platform: Branding, Audience (Internal or External) and Data access (your Gmail scopes). Details in our OAuth consent screen guide.
  4. Create an OAuth client ID under Clients: Web application for a SaaS, Desktop app for a script.
  5. Exchange the code for tokens, then send the access token in Authorization: Bearer.
Google Auth Platform: Clients+ Create client
acme-webWeb application, redirect URI setWeb
inbox-scriptDesktop app, for your own accountDesktop
API keyNot accepted by the Gmail APIWon't work
client_id + client_secret OAuth 2.0

Which credential for your tool?

n8n or another no-code tool OAuth2 credential

n8n recommends OAuth2 for Gmail. A service account works only with domain-wide delegation.

A script on your own mailbox Desktop OAuth client

Sign in once, then reuse the refresh token.

A SaaS for external users Web OAuth client

Plus Google's verification for restricted scopes, or a unified API.

An internal Workspace tool Service account

With domain-wide delegation granted by a Workspace admin. See Path 2.

The full walkthrough, with verification, is in our Google OAuth verification guide. Sources: Google's credentials guide and n8n's Google credentials. Last verified: December 4, 2026.

Comparison

The 3 Real Authentication Paths for Gmail API

Every working path ends with an OAuth access token. What changes is who consents, who stores the tokens, and who goes through Google's review.

Path 1Your app
OAuth 2.0 client ID
User consentYes, per user
Personal @gmail.comYes
Multi-tenant SaaSYes
TokensYour code stores and refreshes
Google reviewYour own, for restricted scopes
Outlook and IMAPNo, Gmail only
Path 2Workspace
Service account + delegation
User consentNo, an admin delegates
Personal @gmail.comNo
Multi-tenant SaaSOne Workspace domain
TokensService account key
Google reviewAdmin setup in Workspace
Outlook and IMAPNo, Workspace only
Path 3Managed
Unified API (Unipile)
User consentYes, through hosted auth
Personal @gmail.comYes
Multi-tenant SaaSYes
TokensStored and refreshed by Unipile
Google reviewDone by Unipile for its own OAuth app (CASA Tier 2); yours if you bring your own credentials
Outlook and IMAPYes, same API
Path 1 of 3

Path 1 - OAuth 2.0 Client ID (Multi-Tenant SaaS)

The standard path when your customers connect their own Gmail accounts: the authorization code flow between your app, Google and the user. More on the OAuth flow for email APIs.

01

Create the OAuth client

Web application type, with your redirect URIs.
02

Declare your scopes

Restricted Gmail scopes need Google's verification.
03

Redirect the user

To Google's consent screen, with access_type=offline.
04

Store the tokens

Keep the refresh token server-side, encrypted.
gmail-oauth-flow.js
const { google } = require('googleapis');
const oauth2 = new google.auth.OAuth2(CLIENT_ID, CLIENT_SECRET, REDIRECT_URI);

// 1. Send the user to Google's consent screen
const url = oauth2.generateAuthUrl({
  access_type: 'offline', // returns a refresh token
  scope: ['https://www.googleapis.com/auth/gmail.readonly'],
});

// 2. In your callback: exchange the code, then call Gmail
async function onCallback(code) {
  const { tokens } = await oauth2.getToken(code);
  oauth2.setCredentials(tokens); // store tokens.refresh_token, encrypted
  const gmail = google.gmail({ version: 'v1', auth: oauth2 });
  return gmail.users.messages.list({ userId: 'me' });
}

Uses the googleapis Node.js client, which refreshes the access token for you. Why tokens expire, and when: Google OAuth refresh token.

Path 2 of 3

Path 2 - Service Account + Domain-Wide Delegation (Workspace Internal)

For internal tools in your own Google Workspace organization. An admin grants the service account access to chosen Gmail scopes once, and it reads any user's mailbox in the domain without a consent screen. Setup, scopes and code in our Gmail service account and domain-wide delegation guide.

Workspace only, never @gmail.com

Delegation works only inside a Google Workspace domain, and only a Workspace admin can set it up. If your users sign in with personal Gmail addresses, use Path 1 or Path 3. Treat the service account key like a private key.

CASA Tier 2

Connect Gmail today, verify your own app later

Unipile has completed Google's verification and a CASA Tier 2 assessment for its own OAuth app. Connect your users' Gmail accounts through it today, on behalf of each authenticated user, and switch to your own Google credentials whenever you want.

Path 3 of 3

Path 3 - Unified Email API (OAuth Handled for You)

Unipile is an independent technical intermediary. You call it with a real Unipile API key; your users connect their mailbox through hosted authentication, and Unipile calls Gmail on behalf of each authenticated user. See how the Email API works.

One hosted auth link

The user signs in with Google and approves the scopes.

Tokens managed by Unipile

Stored encrypted and refreshed server-side. If a user revokes access, the account becomes disconnected and a webhook tells you.

Gmail, Outlook and IMAP

Same endpoints for every mailbox, with webhooks for new emails.
Connect your mailboxHosted auth
GmailContinue with GoogleGoogle's consent screen opensStep 1
Gmailjane@acme.com approvesRead, send and organize emailStep 2
Back in your appSame flow for Outlook and IMAPrunning
POST https://api.unipile.com/v2/auth/link { "providers": "google" } X-API-KEY

Use Unipile's certified Google credentials, or bring your own

Unipile's Google OAuth appDefault
Included in the per-account price, no Google Cloud project on your side Google verification and CASA Tier 2 assessment completed by Unipile Gmail quotas counted on Unipile's Google project
Your own Google OAuth appWhite label
Your name and logo on Google's consent screen Add your client ID and secret in the dashboard: API calls stay the same Google's verification of your app applies to you

This is not a workaround for Google's security review: the review still applies, and Unipile completed it for its own OAuth app. Unipile is not affiliated with, endorsed by, or sponsored by Google. See the Google OAuth documentation, the Gmail API integration and security and compliance (SOC 2 Type II).

Troubleshooting

Common Errors When You Try to Use an API Key with Gmail

Both errors below are 401 UNAUTHENTICATED with the reason CREDENTIALS_MISSING. The message tells you which one you hit.

401API keys are not supported by this API
CauseThe request carries an API key (?key=AIza...) and no OAuth token.
FixDrop the key. Send an OAuth access token in Authorization: Bearer, from one of the 3 paths above.
401Request is missing required authentication credential
CauseNo credential at all: the Authorization header is missing or empty. The errors array says "Login Required."
FixCheck that your client attaches the token to every call, including after a refresh.

Both responses tested on GET https://gmail.googleapis.com/gmail/v1/users/me/messages on December 4, 2026. For OAuth errors such as invalid_grant or redirect_uri_mismatch, see our guide to Google OAuth errors.

Reference

Gmail API Scopes You'll Actually Need

An API key can't carry scopes; an OAuth token always does. Google classifies most Gmail scopes as restricted, which means verification and a security assessment for apps used by external users. Every scope, with its class, is in our Gmail API scopes guide.

gmail.sendSensitiveSend email on the user's behalf.
gmail.readonlyRestrictedRead messages and settings.
gmail.modifyRestrictedRead, send, label and archive, without permanent delete.
gmail.metadata, gmail.composeRestrictedAlso restricted, like mail.google.com.

Source: Google's Gmail API scopes. Last verified: December 4, 2026.

Decision guide

Decision Tree: Which Auth Method for Your Use Case?

One question settles most cases: whose mailboxes does your app read?

Whose Gmail accounts will your app connect?
Your customers, with personal Gmail or their own Workspace

Path 1: OAuth client ID

Multi-tenant: each user connects their own account through your verified app.

Your own employees, all on one Workspace domain

Path 2: Service account

An admin delegates access once. No consent flow per user.

A mix of Gmail, Outlook and IMAP users

Path 3: Unified API

One integration for every provider: see our email API guide. The equivalent for Outlook alone: our Microsoft Graph email guide.

Gmail API Key vs OAuth FAQ

Quick answers on Gmail API keys, OAuth credentials, service accounts and app passwords.

No. Gmail only serves private user data, so it needs an OAuth 2.0 access token. A request with an API key returns 401 UNAUTHENTICATED with the message "API keys are not supported by this API".

Yes. Every Gmail API request needs an OAuth access token: from user consent (OAuth client ID), from domain-wide delegation (Workspace only), or through a unified API that handles OAuth for you.

An API key identifies your project and only unlocks public data, such as Maps or Translate. An OAuth client ID starts a consent flow in which a user approves your app, and it produces the access and refresh tokens that the Gmail API accepts.

Only in Google Workspace, and only if an admin grants it domain-wide delegation for specific Gmail scopes. It never works for personal @gmail.com accounts. See our domain-wide delegation guide.

Because the Gmail API doesn't accept API keys. Google answers 401 with "API keys are not supported by this API", and its errors array says "Login Required." Send an OAuth access token in the Authorization: Bearer header instead.

Yes. With a unified email API like Unipile, users connect Gmail through a hosted authentication link and Unipile stores and refreshes the tokens. OAuth still happens, through Unipile's verified Google app or your own credentials.

There is no Gmail API key. Creating an OAuth client ID costs nothing, and the Gmail API is free on Google's Standard Tier. Billing applies only to Scaled Tier usage, from April 1, 2027: see Gmail API pricing and quotas.

You don't need one. n8n recommends Google OAuth2 credentials for Gmail: create an OAuth client ID in Google Cloud and paste its ID and secret in n8n. A service account works only with domain-wide delegation.

An app password works only for IMAP, SMTP and POP, for accounts with 2-Step Verification. The Gmail API never accepts it. To call the Gmail API, you need OAuth.

No. Unipile is not affiliated with, endorsed by, or sponsored by Google. It is an independent technical intermediary that accesses Gmail on behalf of each authenticated user who granted OAuth consent.

Still have questions? Our team is here to help.

Talk to an expert