Skip to content

ChatGoogleGenerativeAI raises TypeError when passing httpx.Auth via client_args, no supported path for custom authΒ #1613

@yann-combarnous

Description

@yann-combarnous

Package (Required)

  • langchain-google-genai
  • langchain-google-vertexai
  • langchain-google-community
  • Other / not sure / general

Checked other resources

  • I added a descriptive title to this issue
  • I searched the LangChain documentation and API reference (linked above)
  • I used the GitHub search to find a similar issue and didn't find it
  • I am sure this is a feature request and not a bug report or question

Feature Description

Environment

  • langchain-google-genai version: 4.2.1
  • google-genai version: 1.64.0
  • Python: 3.13.2

Description

There is no supported way to supply a custom httpx.Auth (or equivalent auth callback) to
ChatGoogleGenerativeAI when using a custom base_url (e.g. an enterprise WSO2 proxy that
requires a Bearer token).

Passing auth via client_args raises TypeError β€” the constructor does not accept it and does
not forward it to the underlying google-genai client.

# Raises TypeError:
chat = ChatGoogleGenerativeAI(
    model="gemini-2.0-flash",
    base_url="https://my-proxy.example.com/gemini/",
    google_api_key="unused",
    client_args={"auth": my_httpx_auth},  # TypeError
)

Current workaround

After constructing ChatGoogleGenerativeAI, directly mutate the internal google-genai
_api_client:

chat.client._api_client._httpx_client._auth = wso2_auth

This is fragile and breaks if the internal structure of ChatGoogleGenerativeAI or google-genai
changes.

Expected behavior

ChatGoogleGenerativeAI should accept and forward auth-related constructor arguments to the
underlying google-genai client, or expose a dedicated auth / request_headers parameter
that is applied to every request. This is especially important for enterprise deployments that
route via an API gateway requiring token-based authentication.

Use Case

There is no supported way to supply a custom httpx.Auth (or equivalent auth callback) to
ChatGoogleGenerativeAI when using a custom base_url (e.g. an enterprise WSO2 proxy that
requires a Bearer token).

Proposed Solution

ChatGoogleGenerativeAI should accept and forward auth-related constructor arguments to the
underlying google-genai client, or expose a dedicated auth / request_headers parameter
that is applied to every request. This is especially important for enterprise deployments that
route via an API gateway requiring token-based authentication.

Alternatives Considered

No response

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestgenai`langchain-google-genai` package

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions