GCP Gemini API Developer
IMPORTANT BRANDING NOTE
"Agent Platform" (full name: Gemini Enterprise Agent Platform) was previously named "Vertex AI". Many web resources still use "Vertex AI" branding.
CRITICAL SDK NOTE
The following SDKs are DEPRECATED and must NOT be used:
google-cloud-aiplatform (Python)
@google-cloud/vertexai (Node.js)
google-generativeai (Python - Gemini Developer API SDK)
Use ONLY the unified Gen AI SDK:
- Python:
google-genai (pip install google-genai)
- JavaScript/TypeScript:
@google/genai (npm install @google/genai)
- Go:
google.golang.org/genai (go get google.golang.org/genai)
- Java:
com.google.genai:google-genai
- C#/.NET:
Google.GenAI (dotnet add package Google.GenAI)
Authentication
# Application Default Credentials (ADC) - preferred
export GOOGLE_CLOUD_PROJECT='your-project-id'
export GOOGLE_CLOUD_LOCATION='global' # Use 'global' for automatic region routing
export GOOGLE_GENAI_USE_VERTEXAI=true
Model Selection
gemini-3.1-pro-preview - complex reasoning, coding, research (1M tokens)
gemini-3-flash-preview - fast, balanced, multimodal (1M tokens)
gemini-3.1-flash-lite-preview - high-frequency lightweight tasks
gemini-3-pro-image-preview - image generation and editing
gemini-live-2.5-flash-native-audio - Live Realtime API (bidirectional audio/video)
- DEPRECATED (do not use): gemini-2.0-, gemini-1.5-, gemini-1.0-*, gemini-pro
Quick Start (Python)
from google import genai
client = genai.Client() # picks up env vars automatically
response = client.models.generate_content(
model="gemini-3-flash-preview",
contents="Explain transformer architecture"
)
print(response.text)
Reference Directory
Load only when needed:
| Scenario |
Trigger Keywords |
Reference |
| Text + multimodal |
chat, image, video, audio, streaming |
references/text-multimodal.md |
| Function calling + tools |
tool use, function call, grounding, code execution |
references/tools.md |
| Structured output |
JSON, schema, structured, typed response |
references/structured-output.md |
| Embeddings |
embedding, semantic search, vector |
references/embeddings.md |
| Context caching |
cache, large context, caching tokens |
references/caching.md |
| Batch prediction |
batch, async, large dataset |
references/batch.md |
| Live API |
live, realtime, voice, video streaming, bidirectional |
references/live-api.md |
| Model tuning |
fine-tune, SFT, preference tuning |
references/tuning.md |
| Safety |
safety filter, threshold, harm category |
references/safety.md |
| SDK migration |
migrate, deprecated, upgrade |
references/migration.md |
Core Rules
- ALWAYS use the unified
google-genai SDK family. If user code imports google-cloud-aiplatform, @google-cloud/vertexai, or google-generativeai, flag it as deprecated and provide migration guidance.
- Use
location="global" (global endpoint) by default for automatic capacity routing. Only use a specific region if the user explicitly requests it.
- Initialize the client without parameters when environment variables are set - don't hardcode project/location in code.
gemini-3.1-pro-preview ≠ gemini-3-pro-preview - the latter does NOT exist; use the correct model IDs.
- Context caching (
CachedContent) reduces cost for repeated large contexts (system prompts, documents) - recommend it proactively for production workloads with stable large contexts.
- For production, consult docs for stable model version aliases rather than using
-preview models.
- Batch prediction (
BatchJob) is for async large-dataset inference - use it instead of looping generate_content() for bulk processing.
Official Docs
Security Notes
Read-only advisory. Never embed API keys or service account credentials in code examples. Use ADC and environment variables. Do not call batch jobs or fine-tuning jobs on production data without explicit user approval.
1---2name: techtide-gcp-gemini-api-developer3description: Build, integrate, and debug Gemini API applications on Google Cloud Agent Platform (formerly Vertex AI) using the unified google-genai SDK. Covers text generation, multimodal inputs, function calling, structured output, embeddings, context caching, batch prediction, streaming, Live API (bidirectional voice/video), and model tuning across Python, TypeScript/JavaScript, Go, Java, and C#. Use when building Gemini-powered applications, migrating from deprecated Vertex AI or google-generativeai SDKs, or integrating Gemini capabilities into a GCP-hosted service.4---56# GCP Gemini API Developer78## IMPORTANT BRANDING NOTE910"Agent Platform" (full name: Gemini Enterprise Agent Platform) was previously named "Vertex AI". Many web resources still use "Vertex AI" branding.1112## CRITICAL SDK NOTE1314The following SDKs are DEPRECATED and must NOT be used:15- `google-cloud-aiplatform` (Python)16- `@google-cloud/vertexai` (Node.js)17- `google-generativeai` (Python - Gemini Developer API SDK)1819Use ONLY the unified Gen AI SDK:20- Python: `google-genai` (`pip install google-genai`)21- JavaScript/TypeScript: `@google/genai` (`npm install @google/genai`)22- Go: `google.golang.org/genai` (`go get google.golang.org/genai`)23- Java: `com.google.genai:google-genai`24- C#/.NET: `Google.GenAI` (`dotnet add package Google.GenAI`)2526## Authentication2728```bash29# Application Default Credentials (ADC) - preferred30export GOOGLE_CLOUD_PROJECT='your-project-id'31export GOOGLE_CLOUD_LOCATION='global' # Use 'global' for automatic region routing32export GOOGLE_GENAI_USE_VERTEXAI=true33```3435## Model Selection3637- `gemini-3.1-pro-preview` - complex reasoning, coding, research (1M tokens)38- `gemini-3-flash-preview` - fast, balanced, multimodal (1M tokens)39- `gemini-3.1-flash-lite-preview` - high-frequency lightweight tasks40- `gemini-3-pro-image-preview` - image generation and editing41- `gemini-live-2.5-flash-native-audio` - Live Realtime API (bidirectional audio/video)42- DEPRECATED (do not use): gemini-2.0-*, gemini-1.5-*, gemini-1.0-*, gemini-pro4344## Quick Start (Python)4546```python47from google import genai48client = genai.Client() # picks up env vars automatically49response = client.models.generate_content(50 model="gemini-3-flash-preview",51 contents="Explain transformer architecture"52)53print(response.text)54```5556## Reference Directory5758Load only when needed:5960| Scenario | Trigger Keywords | Reference |61|---|---|---|62| Text + multimodal | chat, image, video, audio, streaming | references/text-multimodal.md |63| Function calling + tools | tool use, function call, grounding, code execution | references/tools.md |64| Structured output | JSON, schema, structured, typed response | references/structured-output.md |65| Embeddings | embedding, semantic search, vector | references/embeddings.md |66| Context caching | cache, large context, caching tokens | references/caching.md |67| Batch prediction | batch, async, large dataset | references/batch.md |68| Live API | live, realtime, voice, video streaming, bidirectional | references/live-api.md |69| Model tuning | fine-tune, SFT, preference tuning | references/tuning.md |70| Safety | safety filter, threshold, harm category | references/safety.md |71| SDK migration | migrate, deprecated, upgrade | references/migration.md |7273## Core Rules7475- ALWAYS use the unified `google-genai` SDK family. If user code imports `google-cloud-aiplatform`, `@google-cloud/vertexai`, or `google-generativeai`, flag it as deprecated and provide migration guidance.76- Use `location="global"` (global endpoint) by default for automatic capacity routing. Only use a specific region if the user explicitly requests it.77- Initialize the client without parameters when environment variables are set - don't hardcode project/location in code.78- `gemini-3.1-pro-preview` ≠ `gemini-3-pro-preview` - the latter does NOT exist; use the correct model IDs.79- Context caching (`CachedContent`) reduces cost for repeated large contexts (system prompts, documents) - recommend it proactively for production workloads with stable large contexts.80- For production, consult docs for stable model version aliases rather than using `-preview` models.81- Batch prediction (`BatchJob`) is for async large-dataset inference - use it instead of looping `generate_content()` for bulk processing.8283## Official Docs8485- https://cloud.google.com/vertex-ai/generative-ai/docs/overview86- https://cloud.google.com/vertex-ai/generative-ai/docs/sdks/overview87- https://cloud.google.com/vertex-ai/generative-ai/docs/context-cache/context-cache-overview8889## Security Notes9091Read-only advisory. Never embed API keys or service account credentials in code examples. Use ADC and environment variables. Do not call batch jobs or fine-tuning jobs on production data without explicit user approval.