Skip to content

client.aio.models.generate_content fails with mTLS error on Vertex AI while sync client works #2282

@jorsj

Description

@jorsj

Environment details

  • Programming language: Python
  • OS: macOS
  • Language runtime version: 3.13
  • Package version: google-genai

Steps to reproduce

  1. Initialize the client for Vertex AI: client = genai.Client(vertexai=True, project='your-project-id')
  2. Call the async method: await client.aio.models.generate_content(model='gemini-2.5-flash', contents='Hello')
  3. Observe the error: Failed to send request to https://aiplatform.mtls.googleapis.com/...

Description / Code to Reproduce

When using the google-genai SDK with vertexai=True, calling the asynchronous method await client.aio.models.generate_content fails with a network error pointing to the mTLS endpoint (aiplatform.mtls.googleapis.com). This suggests the async client is defaulting to mTLS and failing because it expects client certificates.

However, using the synchronous method client.models.generate_content with the exact same configuration works successfully in the same environment.

Here is a complete script to reproduce the behavior:

import asyncio
import os
from google import genai
from google.genai import types

async def main():
    client = genai.Client(
        project=os.environ.get("PROJECT_ID", "your-project-id"),
        vertexai=True,
        location="us-central1",
        http_options=types.HttpOptions(
            api_version="v1",
        ),
    )

    model_name = "gemini-2.5-flash"

    # 1. Try Sync (Works)
    try:
        print("Trying sync call...")
        response = client.models.generate_content(
            model=model_name,
            contents="Hello",
        )
        print("Sync Success!")
    except Exception as e:
        print(f"Sync Error: {e}")

    # 2. Try Async (Fails)
    try:
        print("\nTrying async call...")
        response = await client.aio.models.generate_content(
            model=model_name,
            contents="Hello",
        )
        print("Async Success!")
    except Exception as e:
        print(f"Async Error: {e}")

if __name__ == "__main__":
    asyncio.run(main())

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions