Vertex AI API Key vs ADC in Node.js

Savan PadaliyaNovember 7, 202610 min read

Use an API key with Vertex AI only for prototypes: express mode gives you one in minutes, and billed projects can create one for Gemini calls. Use Application Default Credentials (ADC) for anything in production, because ADC uses short-lived tokens, IAM roles and audit logs. If the console says "API keys are disallowed", your organization has blocked keys by policy, and ADC is the only path forward.

This guide covers the three ways a Node.js app can authenticate to Vertex AI (now documented by Google as Gemini Enterprise Agent Platform), how to enable the API, what the common auth errors mean, and how the @google/genai SDK picks which credential to use. For the full first-time project setup, see Vertex AI Setup for Node.js Apps.

The Three Ways to Authenticate to Vertex AI

Express mode API keyStandard API key (billed project)Application Default Credentials (ADC)
Setup timeMinutesMinutes10 to 30 minutes
Needs a project and billingNo (90-day free tier)YesYes
Credential typeLong-lived stringLong-lived stringShort-lived OAuth token (1 hour)
Identity in audit logsNo caller identityNo caller identityPer user or service account
IAM roles applyNoNoYes
Works with every Vertex AI serviceNo, basic generative AI onlyNo, only APIs that accept keysYes
Can be blocked by org policyYesYesNo
Right forLearning, hackathonsQuick internal toolsProduction

Google's own guidance on its API keys page is short: use an API key for testing and Application Default Credentials for production.

Option 1: Vertex AI Express Mode (API Key, No Project)

Express mode is a preview sign-up path that skips organizations, projects and billing. What you get, per Google's docs:

  • An API key generated at sign-up, managed later on the API Keys page in Agent Studio.
  • A 90-day free tier with no billing details. It is separate from the general Google Cloud free trial.
  • Availability for @gmail.com accounts. Google Workspace accounts are sent to the standard flow instead.
  • A global endpoint with no project or location in the URL, with the key in the x-goog-api-key header.
  • A limited model list with low quotas. Google lists 10 requests per minute for the Gemini 2.5 models (gemini-2.5-pro, gemini-2.5-flash, gemini-2.5-flash-lite).

With the @google/genai SDK, express mode is just vertexai: true plus an API key:

import { GoogleGenAI } from '@google/genai';

const ai = new GoogleGenAI({
  vertexai: true,
  apiKey: process.env.GOOGLE_API_KEY, // express mode key
});

const res = await ai.models.generateContent({
  model: 'gemini-2.5-flash',
  contents: 'Give me three names for a habit-tracking app.',
});

console.log(res.text);

When the 90 days end, or you outgrow the quota, you link a billing account and the same Google account becomes a standard one. At that point, move to ADC.

Option 2: A Standard API Key on a Billed Project

Billed projects can also create API keys for Vertex AI model calls. The code is identical to express mode. The differences are that usage is billed to your project and the key gets the project's normal quotas.

Two limits matter. First, a standard key identifies no one: anyone who has the string can spend your budget, and audit logs cannot tell you who made a call. Second, not every Google Cloud service accepts API keys, so features beyond basic model calls (anything that touches your data, such as RAG Engine or Cloud Storage inputs) still need ADC.

If you use a key at all, restrict it in the console to the Vertex AI API, store it in Secret Manager rather than .env files in the repo, and rotate it.

Option 3: Application Default Credentials (Recommended for Production)

ADC is not a credential. It is the lookup strategy Google's client libraries use to find one. In order, ADC checks:

  1. The GOOGLE_APPLICATION_CREDENTIALS environment variable (a path to a JSON credential file).
  2. Your local gcloud ADC file, created by gcloud auth application-default login.
  3. The attached service account of the environment you are running in (Cloud Run, GKE, Compute Engine, Cloud Functions), read from the metadata server.

Local development:

gcloud auth application-default login
# Optional: act as the production service account to catch IAM gaps early
gcloud auth application-default login --impersonate-service-account=app-sa@YOUR_PROJECT.iam.gserviceaccount.com

Production on Cloud Run: create a service account, grant it roles/aiplatform.user, and deploy with --service-account. ADC finds it automatically with no key file. Deploy Node.js AI Apps to Cloud Run walks through the full deployment.

Code: with ADC, you pass project and location and no key:

import { GoogleGenAI } from '@google/genai';

const ai = new GoogleGenAI({
  vertexai: true,
  project: process.env.GOOGLE_CLOUD_PROJECT,
  location: 'global',
});

const res = await ai.models.generateContent({
  model: 'gemini-2.5-flash',
  contents: 'Summarize our refund policy in one sentence: ...',
});

ADC also works with the OpenAI SDK through Vertex AI's OpenAI-compatible endpoint, which accepts only Google Cloud auth. OpenAI SDK with Vertex AI in Node.js shows how to turn ADC into a refreshing access token for that client.

Fixing "API keys are disallowed. Please use Application Default Credentials (ADC) instead"

This message appears on the Vertex AI API keys screen when your organization's security policy blocks API keys. The full text reads roughly: "API keys are disallowed. Your organization's security policy disallows API keys. Please use Application Default Credentials (ADC) instead."

What it means:

  • It is a deliberate admin control, not a bug. Many companies turn it on by default because keys are long-lived secrets that leak into repos and logs.
  • You cannot override it from inside your project. Only an org policy administrator can change it.
  • Google's docs also describe a default org policy, constraints/iam.managed.disableServiceAccountApiKeyCreation, that blocks binding API keys to service accounts. The fix is the same: use ADC.

What to do:

  1. Locally: run gcloud auth application-default login and remove apiKey from your client constructor.
  2. In production: attach a service account with roles/aiplatform.user to your runtime.
  3. Check your environment variables. If GOOGLE_API_KEY or GEMINI_API_KEY is still set, some tools will keep trying the key path. Unset it.
  4. Only if a key is truly required (for example, a third-party tool that only accepts keys), ask your org admin for an exception scoped to one project. Expect a "no" in regulated companies.

Fixing "Vertex AI JSON key" and Key-Creation Errors

People often search for a "Vertex AI JSON key". That is a service account key file, used with GOOGLE_APPLICATION_CREDENTIALS. It works, but it is the riskiest option: it never expires unless you rotate it, and anyone with the file is that service account.

Many organizations block key-file creation with the iam.disableServiceAccountKeyCreation org policy. If you see that error, do not fight it. Use one of these instead:

  • Service account impersonation for local work (the --impersonate-service-account flag above).
  • Attached service accounts on Cloud Run, GKE or Compute Engine.
  • Workload Identity Federation for workloads outside Google Cloud (GitHub Actions, AWS, on-prem), which swaps an external identity for a short-lived Google token with no key file.

How to Enable the Vertex AI API

Every auth option except express mode needs the API turned on in the project:

gcloud services enable aiplatform.googleapis.com --project=YOUR_PROJECT_ID

In the console: APIs & Services → Library → "Vertex AI API" → Enable. Billing must be active on the project. Then grant the calling identity roles/aiplatform.user:

gcloud projects add-iam-policy-binding YOUR_PROJECT_ID \
  --member="serviceAccount:app-sa@YOUR_PROJECT_ID.iam.gserviceaccount.com" \
  --role="roles/aiplatform.user"

The most common error after enabling is 403 PERMISSION_DENIED on aiplatform.endpoints.predict. It almost always means the identity is missing roles/aiplatform.user, or ADC is picking up a different account than you think. Run gcloud auth application-default print-access-token to confirm ADC works, and check which account it belongs to. If you are new to Google Cloud projects in general, Google Cloud AI: Node.js Setup Guide covers project and billing setup.

How @google/genai Chooses Between an API Key and ADC

@google/genai is Google's current SDK for Gemini on both the Gemini Developer API and Vertex AI. Google marked the older @google-cloud/vertexai package as deprecated in May 2026, so new code should use @google/genai. Reading the SDK source (v3.6), the selection rules are:

  1. Which backend: vertexai: true (or enterprise: true) in the constructor, otherwise the GOOGLE_GENAI_USE_ENTERPRISE or GOOGLE_GENAI_USE_VERTEXAI environment variable. If neither is set, the SDK uses the Gemini Developer API, not Vertex AI.
  2. Which key variable: GOOGLE_API_KEY wins over GEMINI_API_KEY if both are set (the SDK logs a warning).
  3. Explicit beats implicit: constructor options always override environment variables.
  4. Explicit API key with project/location only in the environment: the key is used (express mode).
  5. Explicit project/location with a key only in the environment: ADC is used and the key is dropped.
  6. Both only in the environment: project and location win, so ADC is used.
  7. Explicit googleAuthOptions.credentials always override an API key.

Rule 6 is the source of a common surprise: a stray GOOGLE_API_KEY in your shell looks like it should be used, but if GOOGLE_CLOUD_PROJECT is also set, the SDK goes the ADC route and fails with a credentials error on a machine without ADC configured. Be explicit in the constructor and you never have to think about it.

Which Option Should You Choose?

  1. Trying Gemini on Vertex AI for the first time with a personal Gmail account: express mode.
  2. Internal script on a billed project, org allows keys: a restricted standard API key is acceptable.
  3. Anything customer-facing, anything handling customer data, or any org that blocks keys: ADC with a dedicated service account.

The cost of choosing ADC early is about 20 minutes of setup. The cost of a leaked API key is an unbounded bill and no audit trail of who used it.

Frequently Asked Questions

Can I use an API key with Vertex AI?
Yes, in two cases. Express mode gives @gmail.com users an API key with a 90-day free tier and no project setup, and billed projects can create API keys for Gemini model calls. For production, use Application Default Credentials (ADC), which gives short-lived tokens, IAM roles and per-caller audit logs.

What does "API keys are disallowed, please use Application Default Credentials (ADC) instead" mean?
Your organization's security policy blocks API keys for Vertex AI. You cannot work around it from your project. Use ADC: gcloud auth application-default login locally, and an attached service account with roles/aiplatform.user in production. If you truly need a key, ask your org admin.

How do I enable the Vertex AI API?
Run gcloud services enable aiplatform.googleapis.com --project=YOUR_PROJECT_ID, or enable "Vertex AI API" under APIs & Services in the console. The project needs billing. Express mode users skip this step.

What is Vertex AI express mode?
A preview sign-up path that gives @gmail.com users an API key and a 90-day free tier without an organization, project or billing account. It uses a global endpoint with the key in the x-goog-api-key header and supports a limited set of Gemini models with low rate limits.

How does the @google/genai SDK decide between an API key and ADC?
With vertexai: true, it uses ADC when project and location are set and an API key when only apiKey is set. Constructor options beat environment variables. If both project/location and a key come only from the environment, project and location win.

SP

Savan Padaliya

Technical Partner for Startup Founders. Helps founders build MVPs, scale SaaS products, add AI where it creates leverage, and provides fractional CTO-level leadership.