> ## Documentation Index
> Fetch the complete documentation index at: https://phidatainc.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Google Vertex AI With Credentials

> Authenticate Gemini on Vertex AI with explicit service account credentials.

```python vertexai_with_credentials.py theme={null}
"""
Google Vertexai With Credentials
================================

Cookbook example for `google/gemini/vertexai_with_credentials.py`.
"""

from agno.agent import Agent
from agno.models.google import Gemini

# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------

# To use Vertex AI with explicit credentials, you can pass a
# google.oauth2.service_account.Credentials object to the Gemini class.

# 1. Load your service account credentials (example using a JSON file)
# from google.oauth2 import service_account
# credentials = service_account.Credentials.from_service_account_file('path/to/your/service-account.json')

# For demonstration, we'll assume credentials is provided
credentials = None  # Replace with your actual credentials object

# 2. Initialize the Gemini model with the credentials parameter
model = Gemini(
    id="gemini-3.5-flash",
    vertexai=True,
    project_id="your-google-cloud-project-id",
    location="us-central1",
    credentials=credentials,
)

# 3. Create the Agent
agent = Agent(model=model, markdown=True)

# 4. Use the Agent
agent.print_response(
    "Explain how explicit credentials help in production environments."
)

# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------

if __name__ == "__main__":
    pass
```

## Run the Example

<Steps>
  <Snippet file="create-venv-step.mdx" />

  <Step title="Install dependencies">
    ```bash theme={null}
    uv pip install -U agno google-genai
    ```
  </Step>

  <Step title="Provide service account credentials">
    Load a `google.oauth2.service_account.Credentials` object and replace the placeholder project ID before running the example.
  </Step>

  <Step title="Run the example">
    Save the code above as `vertexai_with_credentials.py`, then run:

    ```bash theme={null}
    python vertexai_with_credentials.py
    ```
  </Step>
</Steps>

Full source: [cookbook/90\_models/google/gemini/vertexai\_with\_credentials.py](https://github.com/agno-agi/agno/blob/main/cookbook/90_models/google/gemini/vertexai_with_credentials.py)
