3
3
import os
4
4
from typing import Literal , overload
5
5
6
+ import httpx
7
+
6
8
from pydantic_ai .exceptions import UserError
7
9
from pydantic_ai .models import get_user_agent
8
10
from pydantic_ai .profiles import ModelProfile
12
14
try :
13
15
from google import genai
14
16
from google .auth .credentials import Credentials
17
+ from google .genai .types import HttpOptionsDict
15
18
except ImportError as _import_error :
16
19
raise ImportError (
17
20
'Please install the `google-genai` package to use the Google provider, '
@@ -89,17 +92,17 @@ def __init__(
89
92
if vertexai is None :
90
93
vertexai = bool (location or project or credentials )
91
94
95
+ http_options : HttpOptionsDict = {
96
+ 'headers' : {'User-Agent' : get_user_agent ()},
97
+ 'async_client_args' : {'transport' : httpx .AsyncHTTPTransport ()},
98
+ }
92
99
if not vertexai :
93
100
if api_key is None :
94
101
raise UserError ( # pragma: no cover
95
102
'Set the `GOOGLE_API_KEY` environment variable or pass it via `GoogleProvider(api_key=...)`'
96
103
'to use the Google Generative Language API.'
97
104
)
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 )
103
106
else :
104
107
self ._client = genai .Client (
105
108
vertexai = vertexai ,
@@ -111,7 +114,7 @@ def __init__(
111
114
# For more details, check: https://cloud.google.com/vertex-ai/generative-ai/docs/learn/locations#available-regions
112
115
location = location or os .environ .get ('GOOGLE_CLOUD_LOCATION' ) or 'us-central1' ,
113
116
credentials = credentials ,
114
- http_options = { 'headers' : { 'User-Agent' : get_user_agent ()}} ,
117
+ http_options = http_options ,
115
118
)
116
119
else :
117
120
self ._client = client
0 commit comments