Skip to content

httpx client closed prematurely upon generate_content if the google.genai.Client is used as a temporary object #1763

@jasons1425

Description

@jasons1425

Environment details

  • Programming language: Python
  • Language runtime version: 3.10.19
  • Package version: 1.52.0 (httpx 0.28.1)

Steps to reproduce

from google.genai import Client as GoogleGenAIClient
from google.genai.types import Content, Part

def make_client():
  return GoogleGenAIClient(vertexai=True, location="global")

contents = [Content(role="user", parts=[Part.from_text(text="hello world")])]

// this will cause httpx client closed error
make_client().models.generate_content(model="gemini-2.0-flash-001", contents=contents)

// ...
//  File "/opt/venv/lib/python3.10/site-packages/httpx/_client.py", line 901, in send
//    raise RuntimeError("Cannot send a request, as the client has been closed.")

// this will succeed
client = make_client()
client.models.generate_content(model="gemini-2.0-flash-001", contents=contents)

Metadata

Metadata

Assignees

Labels

api: vertex-aiIssues related to the Vertex AI API.priority: p2Moderately-important priority. Fix may not be included in next release.status:awaiting user responsetype: 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