Halloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowHalloween DealsAmazon USOctober picks are moving - compare before checkoutAmazon US: current deals, useful picks and tech finds.See Picks×
FREEDOM251

Freedom251 › Blog › cloud APIs

How to run Gemini models on Google Vertex AI: a complete setup and production guide

By Freedom251 Team · · 10 min read

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To run Gemini on Vertex AI, you need a billed Google Cloud project, the Vertex AI API enabled, credentials with permission to use Vertex AI, and a current Google Gen AI SDK. Set GOOGLE_CLOUD_PROJECT, GOOGLE_CLOUD_LOCATION (the quickstart uses global) and GOOGLE_GENAI_USE_VERTEXAI=True, then call client.models.generate_content with a supported Gemini model ID. The practical workflow is: prepare Google Cloud, authenticate, install an SDK, make a small request, choose a model deliberately, and add quota, cost and lifecycle controls before production.

Model IDs, prices, quotas, regions and endpoint status change. Check the current supported-models reference, pricing page and release notes immediately before deployment.

As an Amazon Associate I earn from qualifying purchases.

What you need before the first request

  • A Google Cloud project with billing enabled. You can select an existing project or create one in the Google Cloud Console.
  • The Vertex AI API enabled for that project.
  • Local Google Cloud credentials, a service-account identity, or an approved API-key route. Application Default Credentials (ADC) are the documented choice for local development.
  • The roles/aiplatform.user IAM role, or a custom role containing equivalent permissions, granted by a project administrator.
  • A supported Gemini model ID and a location that meets your latency and data-residency requirements.
  • A current Google Gen AI SDK for your language, or an OAuth bearer token for direct REST calls.

The official Vertex AI quickstart is the authority for the current setup sequence and labels. Permissions can be narrower or broader in a controlled enterprise role, but granting more access than the application needs increases risk.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Understand the Vertex AI request path

Your application sends a generateContent request to a Google-published Gemini model in a selected Google Cloud location. Vertex AI applies IAM, quota and billing controls, routes the request to the model endpoint, and returns generated content plus metadata such as usage information when available. The Google Gen AI SDK hides most HTTP details; REST exposes the endpoint directly.

Vertex AI Model Garden is the discovery layer for Google proprietary, partner and open models. It supports model testing, customization, tuning, evaluation and serving. Google Cloud says the garden contains more than 200 enterprise-ready models, while the generative-AI overview describes Gemini capabilities including multimodal text, image, video and audio processing, grounding with Google Search, Maps or private data, embeddings, tuning, evaluation, agents, image generation and video generation. That same 2025 Google Cloud overview describes a 2-million-token Gemini context window; confirm the limit for the specific model and endpoint you select.

Prepare a Google Cloud project and credentials

  1. Open the Google Cloud Console and select an existing project or create a new one.
  2. Verify that billing is attached. A project without an active billing account cannot use the normal paid Vertex AI workflow.
  3. Enable the Vertex AI API for the project.
  4. Install the Google Cloud CLI, then initialize it with gcloud init. Choose the correct account, project and, when prompted, configuration.
  5. Create local ADC with gcloud auth application-default login. Complete the browser sign-in with the identity that is allowed to call Vertex AI.
  6. Ask a project administrator to grant roles/aiplatform.user, or an equivalent custom role, to the user or service identity that will make requests.

For a deployed service, prefer a dedicated service account and workload identity mechanism supported by your runtime rather than copying a personal credential file onto a server. Never commit ADC files, service-account keys, API keys or bearer tokens to source control, logs or client-side code. Apply least-privilege IAM and rotate any credential that may have been exposed.

Install the Google Gen AI SDK

Google’s current cross-language SDK is the Google Gen AI SDK. Use the package manager command for the language you actually deploy, then pin and test a known SDK version in your application’s dependency lockfile.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Language Install command Reference
Python pip install --upgrade google-genai Google Gen AI SDK overview
Node.js npm install @google/genai
Go go get google.golang.org/genai
Java Maven dependency com.google.genai:google-genai

The quickstart contains language-specific initialization and request examples. SDK APIs evolve, so check the version-specific reference if an example does not compile or a parameter has moved.

Set the environment and make a minimal Python call

Set the project, location and Vertex AI switch in the shell that will run your program. The quickstart uses the global location:

export GOOGLE_CLOUD_PROJECT='YOUR_PROJECT_ID'
export GOOGLE_CLOUD_LOCATION='global'
export GOOGLE_GENAI_USE_VERTEXAI=True

After ADC is available, this is the smallest official-style Python request:

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

client = genai.Client(http_options=HttpOptions(api_version='v1'))
response = client.models.generate_content(
    model='gemini-2.5-flash',
    contents='How does AI work?',
)
print(response.text)

Replace gemini-2.5-flash with a model ID that is currently supported in your chosen location. The v1 API version makes the request target explicit; preview-only features can use a different version when the model documentation requires it.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What a successful first call proves

  • The SDK can find your project and location.
  • ADC resolves to an identity with Vertex AI permission.
  • The selected model is available at that endpoint.
  • Your request is syntactically valid and can consume quota and incur token charges.

Keep the first prompt short. A small successful call separates authentication and endpoint problems from application-level prompt, schema or context issues.

Use Node.js, Go, Java or REST when Python is not the fit

Node.js, Go and Java

Install the package shown above and follow the matching examples in the multilanguage quickstart. The same three environment variables and ADC approach apply. Keep the model ID, location and API version in configuration so an operational change does not require editing business logic.

Direct REST

REST is useful for a minimal dependency footprint, a language without an SDK, or a diagnostic request. First obtain a short-lived OAuth token:

gcloud auth print-access-token

Send a POST request to this exact resource pattern, replacing each uppercase variable:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
https://${API_ENDPOINT}/v1/projects/${GOOGLE_CLOUD_PROJECT}/locations/${GOOGLE_CLOUD_LOCATION}/publishers/google/models/${MODEL_ID}:generateContent

Use the bearer token in the Authorization header and a JSON body containing the request’s contents. The endpoint, request schema and complete curl example are maintained in the official quickstart. Do not treat an access token printed in a terminal transcript as a permanent credential.

Choose a Gemini model instead of copying an old model ID

Start in Model Garden and filter by modality, task, lifecycle status, region and deployment option. Then confirm the exact ID in the supported-models page. “Gemini” is a family, not one interchangeable endpoint: capability, reasoning behavior, context, latency, price and availability differ by version.

Decision axis Questions to answer
Capability and modality Do you need text only, image/audio/video input, image or video generation, embeddings, grounding, tuning or agent features?
Context and reasoning What is the documented context limit for this model, and are thinking or other reasoning controls available?
Latency and throughput What response time and sustained request rate does the application require?
Economics What are input, output, thinking, grounding and tool charges for the chosen model?
Location and residency Can the model run in the required region or global endpoint under your data-handling policy?
Capacity Will pay-as-you-go quota be sufficient, or do you need Provisioned Throughput?
Lifecycle Is the endpoint preview, GA, deprecated or scheduled for shutdown?
API compatibility Does the SDK and API version you pin support the model’s request and response features?

Aliases versus explicit versions

Aliases are convenient for experiments but can move to a newer model behavior. If production capacity reservations depend on a particular version, use that model-version ID explicitly. Google documents that Provisioned Throughput does not guarantee requests made indirectly by products such as Vertex AI Search or Agent products; route reserved traffic through the supported model endpoint and verify the reservation’s terms.

Authentication choices and location decisions

Application Default Credentials

ADC is the documented local-development path: run gcloud auth application-default login, then let the SDK discover the credential. In hosted environments, provide credentials through the platform’s supported service-account or workload-identity integration.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

API keys and Vertex AI express mode

The quickstart also documents API-key authentication choices, including Vertex AI express mode. Use an API key only where its restrictions, storage and exposure model are acceptable. A browser or mobile application should not embed a powerful unrestricted key.

Choose a location deliberately

Location affects latency, supported models, residency and sometimes capacity. The quickstart’s sample uses global, but that is not a universal answer. Confirm current location support in the model and location documentation, and document why the selected endpoint satisfies your legal, contractual and operational requirements.

Understand current token pricing before estimating cost

The following figures are listed in USD on Google Cloud’s pricing page and were published by Google Cloud for 2025. They are token rates, not a fixed monthly subscription, and prices or model availability can change. Recheck the live pricing page for your region, model version and any additional grounding or tool charges.

Model and traffic Published rate Qualification
Gemini 2.5 Pro input $1.25 per 1 million tokens Input up to 200,000 tokens; Google Cloud, 2025
Gemini 2.5 Pro text output $10 per 1 million tokens Google Cloud, 2025
Gemini 2.5 Flash input $0.15 per 1 million tokens Google Cloud, 2025
Gemini 2.5 Flash non-thinking text output $0.60 per 1 million tokens Google Cloud, 2025; non-thinking output

Estimate input and output separately. A long prompt, conversation history, retrieved documents and multimodal parts all affect usage. Add any applicable grounding, tool, tuning, storage or other service charges shown on the current pricing page. Set budgets and alerts, cap maximum output where appropriate, and log token usage without logging sensitive prompt contents.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Quotas, Dynamic Shared Quota and HTTP 429 errors

Dynamic Shared Quota (DSQ) is the default pay-as-you-go model described by Google. It has no predefined usage limit, but requests can still receive HTTP 429 when the shared pool is temporarily exhausted. A 429 is therefore not proof that your project has permanently exceeded a numeric quota.

Implement bounded retries with backoff

  1. Retry only errors documented as transient, including capacity-related 429 responses and suitable 5xx responses.
  2. Use exponential backoff with jitter, for example delays that grow from roughly one second to several seconds, and impose a maximum attempt count or wall-clock deadline.
  3. Honor a server-provided retry hint when present.
  4. Limit concurrency before increasing it again; an unbounded worker pool can turn a temporary shortage into a sustained surge.
  5. Record request ID, model, location, status, latency and attempt count, but redact prompts and credentials.
  6. After the retry budget is exhausted, return a clear, retryable failure to the caller or queue the work for later.

Do not retry malformed requests, permission failures or unsupported model errors as if they were capacity problems. Those require configuration or IAM changes.

When to consider Provisioned Throughput

Provisioned Throughput reserves a fixed amount of throughput for a chosen location and model. It is appropriate when predictable capacity and latency matter more than the flexibility of DSQ. Compare the reservation’s committed capacity and cost with your measured demand, and verify that every traffic path actually targets the reserved model endpoint.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Use optional code execution safely

Code execution can be enabled as a tool in a generateContent request. Gemini can generate and run Python iteratively, which is useful for calculations and data transformations that fit the tool’s constraints. The documented service does not support file I/O and imposes a 30-second maximum runtime. Treat generated code and its output as untrusted: validate results, constrain prompts, and do not use the feature as a way to grant the model access to your filesystem, network or secrets.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Check the request syntax and current limitations in the code execution API reference.

Production checklist

  • Pin the SDK version and test upgrades in a staging project.
  • Use an explicit model-version ID when a reservation, evaluation baseline or regulated workflow depends on stable behavior.
  • Store project, location, model and API-version settings outside application code.
  • Grant only the IAM permissions the runtime needs; separate development, staging and production identities.
  • Keep secrets out of repositories, images, client bundles and ordinary logs.
  • Set budgets, billing alerts and per-request output limits.
  • Track request volume, token counts, latency, status codes, retries and model version.
  • Load-test at realistic concurrency and decide whether DSQ is adequate or Provisioned Throughput is justified.
  • Confirm that grounding, tool use, data residency and retention settings match your policy.
  • Review the model page, pricing, quota documentation and release notes before each major deployment.

Troubleshoot the failures you are most likely to see

Permission denied or unauthenticated

Confirm the active account, run gcloud auth application-default login again if the local ADC is stale, check the project selected by GOOGLE_CLOUD_PROJECT, and ask an administrator to verify roles/aiplatform.user or equivalent permissions. Do not “fix” an IAM error by distributing a broad service-account key.

Model not found or unavailable

Check spelling, lifecycle status, API version and location against the supported-models reference. A model can exist in documentation yet be unavailable in a particular region or on a retired preview endpoint.

HTTP 429

Apply the bounded backoff strategy above, reduce burst concurrency, and inspect the current quota and throughput guidance. If predictable capacity is a requirement, evaluate Provisioned Throughput rather than assuming repeated retries create capacity.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Unexpected cost

Inspect input history and output lengths, verify the model actually used, account for multimodal and grounding/tool charges, and compare token telemetry with the current pricing page. A model alias change can alter both behavior and rate.

Preview endpoint or SDK breakage

Read the release notes for shutdown dates and migration instructions. Google’s June 2025 notes announced Gemini 2.5 Pro and Flash general availability and preview endpoint shutdowns after July 15, 2025; treat that example as a reminder to verify today’s status rather than as a permanent schedule.

Keep the integration current

Before shipping or renewing a production deployment, recheck five values together: model ID, region, pricing, quota behavior and SDK/API compatibility. Also review deprecation notices and release notes. A working quickstart can stop being a safe production configuration when an alias advances, a preview endpoint closes, a location changes support, or pricing is revised.

For a new integration, the safest sequence is to prove one small authenticated request, select a documented model version for the actual workload, measure tokens and latency, add bounded retries and monitoring, and only then scale traffic or reserve capacity.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

cloud APIsDeveloper GuideGeminigenerative AIGoogle CloudGoogle Vertex AI

Leave a Reply

Your email address will not be published. Required fields are marked *

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.