33import os
44from typing import Literal , overload
55
6+ import httpx
7+
68from pydantic_ai .exceptions import UserError
79from pydantic_ai .models import get_user_agent
810from pydantic_ai .profiles import ModelProfile
1214try :
1315 from google import genai
1416 from google .auth .credentials import Credentials
17+ from google .genai .types import HttpOptionsDict
1518except ImportError as _import_error :
1619 raise ImportError (
1720 'Please install the `google-genai` package to use the Google provider, '
@@ -89,17 +92,17 @@ def __init__(
8992 if vertexai is None :
9093 vertexai = bool (location or project or credentials )
9194
95+ http_options : HttpOptionsDict = {
96+ 'headers' : {'User-Agent' : get_user_agent ()},
97+ 'async_client_args' : {'transport' : httpx .AsyncHTTPTransport ()},
98+ }
9299 if not vertexai :
93100 if api_key is None :
94101 raise UserError ( # pragma: no cover
95102 'Set the `GOOGLE_API_KEY` environment variable or pass it via `GoogleProvider(api_key=...)`'
96103 'to use the Google Generative Language API.'
97104 )
98- self ._client = genai .Client (
99- vertexai = vertexai ,
100- api_key = api_key ,
101- http_options = {'headers' : {'User-Agent' : get_user_agent ()}},
102- )
105+ self ._client = genai .Client (vertexai = vertexai , api_key = api_key , http_options = http_options )
103106 else :
104107 self ._client = genai .Client (
105108 vertexai = vertexai ,
@@ -111,7 +114,7 @@ def __init__(
111114 # For more details, check: https://cloud.google.com/vertex-ai/generative-ai/docs/learn/locations#available-regions
112115 location = location or os .environ .get ('GOOGLE_CLOUD_LOCATION' ) or 'us-central1' ,
113116 credentials = credentials ,
114- http_options = { 'headers' : { 'User-Agent' : get_user_agent ()}} ,
117+ http_options = http_options ,
115118 )
116119 else :
117120 self ._client = client
0 commit comments