Skip to content

Commit 3ae5e6c

Browse files
authored
Use httpx on GoogleProvider (#2438)
1 parent 505b594 commit 3ae5e6c

File tree

1 file changed

+9
-6
lines changed
  • pydantic_ai_slim/pydantic_ai/providers

1 file changed

+9
-6
lines changed

pydantic_ai_slim/pydantic_ai/providers/google.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import os
44
from typing import Literal, overload
55

6+
import httpx
7+
68
from pydantic_ai.exceptions import UserError
79
from pydantic_ai.models import get_user_agent
810
from pydantic_ai.profiles import ModelProfile
@@ -12,6 +14,7 @@
1214
try:
1315
from google import genai
1416
from google.auth.credentials import Credentials
17+
from google.genai.types import HttpOptionsDict
1518
except 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

Comments
 (0)