File, Config or Environment Variable?

Created on 24 April 2025, 2 days ago

Problem/Motivation

This could be explained better both here:
https://www.drupal.org/project/ai_provider_google_vertex

And when setting up the provider docs here:
/admin/config/ai/providers/google_vertex

What I see on the Setup Google Vertex is:

General Google Credentials File
Choose an available key. If the desired key is not listed, create a new key. The location of a Google Credentials File. Read more under https://cloud.google.com/docs/authentication/application-default-credent....

Is this actually referring to a “Google Credentials File” or .key file or a generic a JSON file for a service account, not a .key file in the traditional sense (like SSH).

I'm fine with a JSON file contains private keys for me to authenticate with Vertex AI, but I'm not seeing that information in:
https://cloud.google.com/docs/authentication/application-default-credent...

I'm just not seeing a way to download a file for which to use the API key. Now I had tried with setting the API key I've generated in a config setting, but am enccountering this error:

AiRequestErrorException: Error invoking model response: Could not construct ApplicationDefaultCredentials

I could possibly set it in the environment variables too (but not sure if that will work with Google Vertex as it is now.

Steps to reproduce

See above.

Proposed resolution

More documentation on what works and verified URLs.

Remaining tasks

User interface changes

API changes

Data model changes

📌 Task
Status

Active

Version

1.1

Component

Documentation

Created by

🇨🇦Canada mgifford Ottawa, Ontario

Live updates comments and jobs are added and updated live.
  • Documentation

    Primarily changes documentation, not code. For Drupal core issues, select the Documentation component instead of using this tag. In general, component selection is preferred over tag selection.

Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @mgifford
  • 🇨🇦Canada mgifford Ottawa, Ontario

    Asking ChatGPT Led me to https://console.cloud.google.com/iam-admin/serviceaccounts/details/YOUR_...

    And the info I was missing:

    4. Create JSON Key
    • Click the service account you just created.
    • Go to the “Keys” tab.
    • Click Add Key > Create New Key
    • Select JSON
    • Click Create

    A .json file (not .key) will download — this is the “key file” Drupal is asking for.

    It was there in my download file, I just hadn't noticed it.

  • 🇺🇸United States Owen Barton

    The other missing detail here is that it needs to be added with the key provider "Configuration" (not File!) which was a bit confusing.

  • 🇧🇬Bulgaria valthebald Sofia

    I see 2 parts here:
    1. Although Vertex authentication should be done via JSON file, keys of type "File" do not work. This is a bug that is easily fixable in VertexProvider::getAccessToken() - which should try to unserialize the key before creating ServiceAccountCredentials
    2. (working) keys of type environment/configuration should be documented better. This part specifically?

    Could explain that the key should be in fact the path to the JSON file (which is a bit controversial)

  • 🇧🇬Bulgaria valthebald Sofia

    What if, to avoid confusion, we limit selection of keys in provider form to only file-based? Suggested MR does just that, and changes a little description of the key select to

    Choose an available key. If the desired key is not listed, create a new key. Important: Key must use "File" provider and point to the JSON credentials file. Read more at https://cloud.google.com/docs/authentication/application-default-credent....

    One thing to decide is whether we need an update hook to switch from config/environment key to file based for existing installations.

  • 🇧🇬Bulgaria valthebald Sofia

    I added hook_update_N() just in case

  • 🇨🇦Canada mgifford Ottawa, Ontario

    Thanks @valthebald just scanned the code. Looks good to me. I'll try to test the patch.

Production build 0.71.5 2024