Skip to content

GenAIGenerativeModelHook.get_genai_client() ignores Airflow connection credentials — falls back to ADC #65709

Description

@yershovkiril

Under which category would you file this issue?

Providers

Apache Airflow version

providers-google 21.1.0 (Airflow 3.2.1)

What happened and how to reproduce it?

GenAIGenerateContentOperator raises DefaultCredentialsError even when gcp_conn_id is set to a valid connection with a service account key.

The root cause is in GenAIGenerativeModelHook.get_genai_client():

providers/google/cloud/hooks/gen_ai.py

def get_genai_client(self, project_id: str, location: str):
return genai.Client(
vertexai=True,
project=project_id,
location=location,
)

The credentials parameter is not passed to genai.Client, so it falls back to Application Default Credentials. In environments where credentials are managed via Airflow
connections (e.g. Docker containers with service account keys), ADC doesn't exist and the call fails.

How to reproduce

  1. Configure a GCP connection in Airflow using a service account JSON key (not ADC)
  2. Use GenAIGenerateContentOperator with that gcp_conn_id
  3. Run in an environment without ADC configured (e.g. Docker)

What you think should happen instead?

The hook should pass the connection's credentials to the client, same as the old GenerativeModelHook did with vertexai.init(credentials=self.get_credentials()).

Operating System

Ubuntu 20.04.6 LTS

Deployment

Docker-Compose

Apache Airflow Provider(s)

google

Versions of Apache Airflow Providers

apache-airflow-providers-google==21.1.0

Official Helm Chart version

Not Applicable

Kubernetes Version

No response

Helm Chart configuration

No response

Docker Image customizations

No response

Anything else?

No response

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:providerskind:bugThis is a clearly a bugneeds-triagelabel for new issues that we didn't triage yetprovider:googleGoogle (including GCP) related issues

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions