Skip to content

Commit 34c7505

Browse files
GWealecopybara-github
authored andcommitted
docs(gemini): show subclass pattern for custom Client config
Documents the existing subclass pattern (cached_property override of api_client) so users with non-default genai.Client config — location, project, credentials, http_options — find it without trial and error. Several #3628 commenters rediscovered this independently; making it discoverable in the class docstring should reduce repeat issues. Replaces an earlier draft of this CL that added a public client= field on Gemini. The framework already supports the use case via subclassing, so a docstring expansion is sufficient and avoids new public API. Close #3628 Co-authored-by: George Weale <gweale@google.com> PiperOrigin-RevId: 905258437
1 parent 78a8851 commit 34c7505

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

src/google/adk/models/google_llm.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,25 @@ class Gemini(BaseLlm):
9191
model: The name of the Gemini model.
9292
use_interactions_api: Whether to use the interactions API for model
9393
invocation.
94+
95+
Customizing the underlying Client:
96+
To set ``google.genai.Client`` options ADK doesn't expose as fields
97+
directly (location, project, credentials, http_options, etc.),
98+
subclass ``Gemini`` and override the ``api_client`` property::
99+
100+
from functools import cached_property
101+
from google.adk.models import Gemini
102+
from google.genai import Client
103+
104+
class GlobalGemini(Gemini):
105+
@cached_property
106+
def api_client(self) -> Client:
107+
return Client(vertexai=True, location="global")
108+
109+
agent = Agent(model=GlobalGemini(model="gemini-3-pro-preview"))
110+
111+
Use ``@property`` instead of ``@cached_property`` if you hit asyncio
112+
lock contention in multithreaded code.
94113
"""
95114

96115
model: str = 'gemini-2.5-flash'

0 commit comments

Comments
 (0)