How to Access the Gemini 2.5 Pro API Using the Google Cloud Free Trial

Ben Makansi
April 10, 2026

I spent part of today trying to get Gemini 2.5 Pro working through the GCP free trial, hit a few dead ends, and eventually got it working. Here's the situation.

Why Google AI Studio won't work

Google moved Gemini 2.5 Pro off the free tier in April 2026. Your first instinct might be to sign up for the $300 GCP free trial and use those credits in AI Studio. That won't work. Google AI Studio is explicitly listed as an exemption from the GCP free trial. The credits don't apply there.

The path that works is Vertex AI, which is covered by the free trial.

Enable the Vertex AI API

Sign up for the free trial at cloud.google.com/free if you haven't already. Then in the Google Cloud Console, go to APIs & Services > Library, search for "Vertex AI API," and enable it for your project.

Don't bother trying to create an API key

When I tried to set up an API key for Vertex AI through the Credentials page, I hit a circular UI bug. Checking "Authenticate through service account" clears the API restrictions dropdown, but the form won't save without an API restriction selected. And you can't complete the service account binding without first picking an API restriction. There's no way out of that loop in the UI.

But even if you get past that somehow, it doesn't matter. Vertex AI's endpoint doesn't accept API keys at all:

$ curl -X POST \
 -H "x-goog-api-key: YOUR_KEY" \
 -H "Content-Type: application/json" \
 "https://us-central1-aiplatform.googleapis.com/v1/projects/YOUR_PROJECT/locations/us-central1/publishers/google/models/gemini-2.5-pro:generateContent" \
 -d '{"contents":[{"role":"user","parts":[{"text":"Say hello"}]}]}'

{
 "error": {
   "code": 401,
   "message": "API keys are not supported by this API. Expected OAuth2 access token or other authentication credentials that assert a principal.",
   "status": "UNAUTHENTICATED"
 }
}

The error message tells you exactly what you need: an OAuth2 access token or credentials that assert a principal. API keys are anonymous and don't identify a principal, so Vertex AI rejects them.

What actually works: Authenticated Principal (like Application Default Credentials in Cloud Shell)

Vertex AI requires an authenticated identity, not an API key.

The simplest way to get started is with Application Default Credentials (ADC), which is a strategy the Google client libraries use to automatically find credentials in your environment. On Cloud Shell this is YOUR credentials, but it can be any authenticated principal.

The fastest option: Cloud Shell

Cloud Shell is a free terminal inside the Google Cloud Console. Click the >_ icon in the top right corner to open it. It's already authenticated with your Google account, so ADC works immediately with no setup.

Run this, replacing YOUR_PROJECT_ID with your project ID (visible in the project selector at the top of the Console):

curl -X POST \
 -H "Authorization: Bearer $(gcloud auth print-access-token)" \
 -H "Content-Type: application/json" \
 "https://us-central1-aiplatform.googleapis.com/v1/projects/YOUR_PROJECT_ID/locations/us-central1/publishers/google/models/gemini-2.5-pro:generateContent" \
 -d '{"contents":[{"role":"user","parts":[{"text":"Say hello"}]}]}'

When it works, you'll get something like this:

{
 "candidates": [{
   "content": {
     "role": "model",
     "parts": [{"text": "Hello there! How can I help you today?"}]
   },
   "finishReason": "STOP"
 }],
 "usageMetadata": {
   "trafficType": "ON_DEMAND"
 },
 "modelVersion": "gemini-2.5-pro"
}

trafficType: "ON_DEMAND" confirms the call went through and is being billed against your trial credits.

On your local machine

You don't have to use Cloud Shell. On your own machine, run:

gcloud auth application-default login

This opens a browser flow, and once you authenticate, ADC is configured locally. The same curl command and Python code from above will work exactly the same way.

Using the Python SDK

If you prefer Python, use the google-genai package. Don't use vertexai.generative_models, that SDK was deprecated in June 2025.

from google import genai
from google.genai.types import HttpOptions

client = genai.Client(
   vertexai=True,
   project="YOUR_PROJECT_ID",
   location="us-central1",
   http_options=HttpOptions(api_version="v1"),
)

response = client.models.generate_content(
   model="gemini-2.5-pro",
   contents="Say hello",
)

print(response.text)

This works in Cloud Shell (where ADC is preconfigured) or on your local machine (after running gcloud auth application-default login).

Note: Any service account with the Vertex AI User role would work

ADC on Cloud Shell is the easiest starting point, but it's not the only way to authenticate with Vertex AI. Any service account identity that has the Vertex AI User role (or broader) can call the endpoint.

What about using an API key with AI Studio?

Your $300 free trial credits won't apply in Google AI Studio. If you sign up for the GCP free trial, you get a billing account, but you would need to convert it to a paid account in order to use Gemini 2.5 Pro in AI Studio. You wouldn't be using your trial credits.

If the whole point of the free trial is to avoid charges, use the Vertex AI approach above instead.

arrow