Skip to content

Commit 077c121

Browse files
authored
fix(auth): update model authentication info (#516)
* fix(auth): update model authentication info * add cloudpickle dependency to AE * update link * Update models.md
1 parent 2747fa3 commit 077c121

File tree

4 files changed

+81
-55
lines changed

4 files changed

+81
-55
lines changed

docs/agents/models.md

Lines changed: 70 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,18 @@ The following sections guide you through using these methods based on your needs
2828

2929
## Using Google Gemini Models
3030

31-
This is the most direct way to use Google's flagship models within ADK.
31+
This section covers authenticating with Google's Gemini models, either through Google AI Studio for rapid development or Google Cloud Vertex AI for enterprise applications. This is the most direct way to use Google's flagship models within ADK.
32+
33+
**Integration Method:** Once you are authenticated using one of the below methods, you can pass the model's identifier string directly to the
34+
`model` parameter of `LlmAgent`.
3235

33-
**Integration Method:** Pass the model's identifier string directly to the
34-
`model` parameter of `LlmAgent` (or its alias, `Agent`).
3536

36-
**Backend Options & Setup:**
37+
!!!tip
3738

38-
The `google-genai` library, used internally by ADK for Gemini, can connect
39-
through either Google AI Studio or Vertex AI.
39+
The `google-genai` library, used internally by ADK for Gemini models, can connect
40+
through either Google AI Studio or Vertex AI.
4041

41-
!!!note "Model support for voice/video streaming"
42+
**Model support for voice/video streaming**
4243

4344
In order to use voice/video streaming in ADK, you will need to use Gemini
4445
models that support the Live API. You can find the **model ID(s)** that
@@ -49,51 +50,76 @@ through either Google AI Studio or Vertex AI.
4950

5051
### Google AI Studio
5152

52-
* **Use Case:** Google AI Studio is the easiest way to get started with Gemini.
53-
All you need is the [API key](https://aistudio.google.com/app/apikey). Best
54-
for rapid prototyping and development.
55-
* **Setup:** Typically requires an API key:
56-
* Set as an environment variable or
57-
* Passed during the model initialization via the `Client` (see example below)
53+
This is the simplest method and is recommended for getting started quickly.
5854

59-
```shell
60-
export GOOGLE_API_KEY="YOUR_GOOGLE_API_KEY"
61-
export GOOGLE_GENAI_USE_VERTEXAI=FALSE
62-
```
55+
* **Authentication Method:** API Key
56+
* **Setup:**
57+
1. **Get an API key:** Obtain your key from [Google AI Studio](https://aistudio.google.com/apikey).
58+
2. **Set environment variables:** Create a `.env` file (Python) or `.properties` (Java) in your project's root directory and add the following lines. ADK will automatically load this file.
59+
60+
```shell
61+
export GOOGLE_API_KEY="YOUR_GOOGLE_API_KEY"
62+
export GOOGLE_GENAI_USE_VERTEXAI=FALSE
63+
```
64+
65+
(or)
66+
67+
Pass these variables during the model initialization via the `Client` (see example below).
6368

6469
* **Models:** Find all available models on the
6570
[Google AI for Developers site](https://ai.google.dev/gemini-api/docs/models).
6671

67-
### Vertex AI
72+
### Google Cloud Vertex AI
6873

69-
* **Use Case:** Recommended for production applications, leveraging Google Cloud
70-
infrastructure. Gemini on Vertex AI supports enterprise-grade features,
71-
security, and compliance controls.
72-
* **Setup:**
73-
* Authenticate using Application Default Credentials (ADC):
74+
For scalable and production-oriented use cases, Vertex AI is the recommended platform. Gemini on Vertex AI supports enterprise-grade features, security, and compliance controls. Based on your development environment and usecase, *choose one of the below methods to authenticate*.
7475

75-
```shell
76-
gcloud auth application-default login
77-
```
76+
**Pre-requisites:** A Google Cloud Project with [Vertex AI enabled](https://console.cloud.google.com/apis/enableflow;apiid=aiplatform.googleapis.com).
7877

79-
* Configure these variables either as environment variables or by providing them directly when initializing the Model.
80-
81-
Set your Google Cloud project and location:
82-
83-
```shell
84-
export GOOGLE_CLOUD_PROJECT="YOUR_PROJECT_ID"
85-
export GOOGLE_CLOUD_LOCATION="YOUR_VERTEX_AI_LOCATION" # e.g., us-central1
86-
```
87-
88-
Explicitly tell the library to use Vertex AI:
78+
### **Method A: User Credentials (for Local Development)**
79+
80+
1. **Install the gcloud CLI:** Follow the official [installation instructions](https://cloud.google.com/sdk/docs/install).
81+
2. **Log in using ADC:** This command opens a browser to authenticate your user account for local development.
82+
```bash
83+
gcloud auth application-default login
84+
```
85+
3. **Set environment variables:**
86+
```shell
87+
export GOOGLE_CLOUD_PROJECT="YOUR_PROJECT_ID"
88+
export GOOGLE_CLOUD_LOCATION="YOUR_VERTEX_AI_LOCATION" # e.g., us-central1
89+
```
8990

90-
```shell
91-
export GOOGLE_GENAI_USE_VERTEXAI=TRUE
92-
```
91+
Explicitly tell the library to use Vertex AI:
9392

94-
* **Models:** Find available model IDs in the
93+
```shell
94+
export GOOGLE_GENAI_USE_VERTEXAI=TRUE
95+
```
96+
97+
4. **Models:** Find available model IDs in the
9598
[Vertex AI documentation](https://cloud.google.com/vertex-ai/generative-ai/docs/learn/models).
9699

100+
### **Method B: Vertex AI Express Mode**
101+
[Vertex AI Express Mode](https://cloud.google.com/vertex-ai/generative-ai/docs/start/express-mode/overview) offers a simplified, API-key-based setup for rapid prototyping.
102+
103+
1. **Sign up for Express Mode** to get your API key.
104+
2. **Set environment variables:**
105+
```shell
106+
export GOOGLE_API_KEY="PASTE_YOUR_EXPRESS_MODE_API_KEY_HERE"
107+
export GOOGLE_GENAI_USE_VERTEXAI=TRUE
108+
```
109+
110+
### **Method C: Service Account (for Production & Automation)**
111+
112+
For deployed applications, a service account is the standard method.
113+
114+
1. [**Create a Service Account**](https://cloud.google.com/iam/docs/service-accounts-create#console) and grant it the `Vertex AI User` role.
115+
2. **Provide credentials to your application:**
116+
* **On Google Cloud:** If you are running the agent in Cloud Run, GKE, VM or other Google Cloud services, the environment can automatically provide the service account credentials. You don't have to create a key file.
117+
* **Elsewhere:** Create a [service account key file](https://cloud.google.com/iam/docs/keys-create-delete#console) and point to it with an environment variable:
118+
```bash
119+
export GOOGLE_APPLICATION_CREDENTIALS="/path/to/your/keyfile.json"
120+
```
121+
Instead of the key file, you can also authenticate the service account using Workload Identity. But this is outside the scope of this guide.
122+
97123
**Example:**
98124
99125
=== "Python"
@@ -157,6 +183,9 @@ export GOOGLE_GENAI_USE_VERTEXAI=FALSE
157183
// different availability or quota limitations.
158184
```
159185
186+
!!!warning "Secure Your Credentials"
187+
Service account credentials or API keys are powerful credentials. Never expose them publicly. Use a secret manager like [Google Secret Manager](https://cloud.google.com/secret-manager) to store and access them securely in production.
188+
160189
## Using Anthropic models
161190
162191
![java_only](https://img.shields.io/badge/Supported_in-Java-orange){ title="This feature is currently available for Java. Python support for direct Anthropic API (non-Vertex) is via LiteLLM."}
@@ -753,4 +782,4 @@ Vertex AI.
753782
}
754783
}
755784
}
756-
```
785+
```

docs/deploy/agent-engine.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Agent Engine is part of the Vertex AI SDK for Python. For more information, you
2626
### Install the Vertex AI SDK
2727

2828
```shell
29-
pip install google-cloud-aiplatform[adk,agent_engines]
29+
pip install "google-cloud-aiplatform[adk,agent_engines]" cloudpickle
3030
```
3131

3232
!!!info

docs/get-started/quickstart.md

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,14 @@ application entirely on your machine and is recommended for internal development
133133

134134
Your agent's ability to understand user requests and generate responses is
135135
powered by a Large Language Model (LLM). Your agent needs to make secure calls
136-
to this external LLM service, which requires authentication credentials. Without
136+
to this external LLM service, which **requires authentication credentials**. Without
137137
valid authentication, the LLM service will deny the agent's requests, and the
138138
agent will be unable to function.
139139

140+
!!!tip "Model Authentication guide"
141+
For a detailed guide on authenticating to different models, see the [Authentication guide](../agents/models.md#google-ai-studio).
142+
This is a critical step to ensure your agent can make calls to the LLM service.
143+
140144
=== "Gemini - Google AI Studio"
141145
1. Get an API key from [Google AI Studio](https://aistudio.google.com/apikey).
142146
2. When using Python, open the **`.env`** file located inside (`multi_tool_agent/`)
@@ -157,17 +161,10 @@ agent will be unable to function.
157161
3. Replace `PASTE_YOUR_ACTUAL_API_KEY_HERE` with your actual `API KEY`.
158162

159163
=== "Gemini - Google Cloud Vertex AI"
160-
1. You need an existing
161-
[Google Cloud](https://cloud.google.com/?e=48754805&hl=en) account and a
162-
project.
163-
* Set up a
164-
[Google Cloud project](https://cloud.google.com/vertex-ai/generative-ai/docs/start/quickstarts/quickstart-multimodal#setup-gcp)
165-
* Set up the
166-
[gcloud CLI](https://cloud.google.com/vertex-ai/generative-ai/docs/start/quickstarts/quickstart-multimodal#setup-local)
167-
* Authenticate to Google Cloud, from the terminal by running
168-
`gcloud auth login`.
169-
* [Enable the Vertex AI API](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com).
170-
2. When using Python, open the **`.env`** file located inside (`multi_tool_agent/`). Copy-paste
164+
1. Set up a [Google Cloud project](https://cloud.google.com/vertex-ai/generative-ai/docs/start/quickstarts/quickstart-multimodal#setup-gcp) and [enable the Vertex AI API](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com).
165+
2. Set up the [gcloud CLI](https://cloud.google.com/vertex-ai/generative-ai/docs/start/quickstarts/quickstart-multimodal#setup-local).
166+
3. Authenticate to Google Cloud from the terminal by running `gcloud auth login`.
167+
4. When using Python, open the **`.env`** file located inside (`multi_tool_agent/`). Copy-paste
171168
the following code and update the project ID and location.
172169

173170
```env title="multi_tool_agent/.env"

mkdocs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ nav:
128128
- Parallel agents: agents/workflow-agents/parallel-agents.md
129129
- Custom agents: agents/custom-agents.md
130130
- Multi-agent systems: agents/multi-agents.md
131-
- Models: agents/models.md
131+
- Models & Authentication: agents/models.md
132132
- Tools:
133133
- tools/index.md
134134
- Function tools: tools/function-tools.md

0 commit comments

Comments
 (0)