You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit ead356e
Browse filesBrowse the repository at this point in the historyBrowse files
feat!: Switch default HTTP client to httpx2 and use OS trust store by default
BREAKING CHANGE: `httpx2` is now the required dependency and default HTTP client
instead of `httpx`, and default SSL verification with `httpx2` uses the OS
certificate trust store (via `truststore` / `httpx2.create_ssl_context()`) when
`SSL_CERT_FILE` and `SSL_CERT_DIR` are not set. To maintain baseline behavior,
install `google-genai[httpx]` and set `GOOGLE_GENAI_HTTP_CLIENT=httpx`.
Summary of impact:
- If your code uses `httpx` or `httpx2` to interact with the SDK, make sure it
uses the same package as the active SDK client.
- In most cases, updating your code with `import httpx2 as httpx` is sufficient.
- The SDK still fully supports both `httpx` and `httpx2`; only the default has
changed.
- `httpx` is no longer installed by default (use `pip install google-genai[httpx]`
to install a compatible version; `google-genai[httpx2]` remains as a no-op
extra).
- You can set the SDK's default backend with `GOOGLE_GENAI_HTTP_CLIENT` (`httpx`
or `httpx2` strictly requires that package; unset or `auto` prefers `httpx2`
and falls back to `httpx` if only `httpx` is installed).
- Regardless of the default, passing `HttpOptions(httpx_client=..., httpx_async_client=...)`
uses those objects directly (sync and async are configured independently).
Where `httpx`/`httpx2` types must match the active client:
- `HttpOptions(client_args=..., async_client_args=...)`: package-specific objects
such as `Timeout`, `MockTransport` / `BaseTransport` (and `Response` objects
from mock handlers), and custom `Auth` subclasses must match the active client.
Primitives (numeric timeouts, auth tuples, proxy URL strings) work with either.
- Transport exceptions on `client.models`, `files`, etc.: network and timeout
errors (`TimeoutException`, `ConnectError`, `HTTPError`) are reraised unwrapped
after retries, so `except` clauses catching them directly must match the active
client. (4xx/5xx `APIError` exceptions and `client.interactions`
`APIConnectionError` / `APITimeoutError` are unchanged, though `.response` /
`.request` attributes come from the active client.)
Fixes: #2680
PiperOrigin-RevId: 1006549935
Copy file name to clipboardExpand all lines: README.md
+13-13Lines changed: 13 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -250,37 +250,37 @@ client = genai.Client(
250
250
)
251
251
```
252
252
253
-
### HTTP client option: httpx2
253
+
### HTTP client option: httpx
254
254
255
-
By default, the SDK uses `httpx` for its HTTP transport. You can opt in to
256
-
[`httpx2`](https://github.com/pydantic/httpx2) by installing `google-genai[httpx2]`
255
+
By default, the SDK uses [`httpx2`](https://github.com/pydantic/httpx2) for its HTTP transport. You can opt in to
256
+
legacy `httpx` by installing `google-genai[httpx]`
257
257
and setting the `GOOGLE_GENAI_HTTP_CLIENT` environment variable:
258
258
259
259
```bash
260
-
export GOOGLE_GENAI_HTTP_CLIENT=httpx2
260
+
export GOOGLE_GENAI_HTTP_CLIENT=httpx
261
261
```
262
262
263
-
Alternatively, you can directly inject an `httpx2.Client` or `httpx2.AsyncClient`
263
+
Alternatively, you can directly inject an `httpx.Client` or `httpx.AsyncClient`
264
264
via `HttpOptions`:
265
265
266
266
```python
267
-
importhttpx2
267
+
importhttpx
268
268
from google import genai
269
269
from google.genai import types
270
270
271
271
client = genai.Client(
272
272
http_options=types.HttpOptions(
273
-
httpx_client=httpx2.Client(),
274
-
httpx_async_client=httpx2.AsyncClient(),
273
+
httpx_client=httpx.Client(),
274
+
httpx_async_client=httpx.AsyncClient(),
275
275
)
276
276
)
277
277
```
278
278
279
279
### Faster async client option: Aiohttp
280
280
281
-
By default we use httpx for both sync and async client implementations. In order
281
+
By default we use httpx2 for both sync and async client implementations. In order
282
282
to have faster performance, you may install `google-genai[aiohttp]`. In Gen AI
283
-
SDK we configure `trust_env=True` to match with the default behavior of httpx.
283
+
SDK we configure `trust_env=True` to match with the default behavior of httpx2.
284
284
Additional args of `aiohttp.ClientSession.request()` ([see `_RequestOptions` args](https://github.com/aio-libs/aiohttp/blob/v3.12.13/aiohttp/client.py#L170)) can be passed
If you need `socks5` proxy, httpx[supports](https://www.python-httpx.org/advanced/proxies/#socks)`socks5` proxy if you pass it via
308
-
args to `httpx.Client()`. You may install `httpx[socks]` to use it.
307
+
If you need `socks5` proxy, httpx2[supports](https://www.python-httpx.org/advanced/proxies/#socks)`socks5` proxy if you pass it via
308
+
args to `httpx2.Client()`. You may install `httpx2[socks]` to use it.
@@ -237,7 +237,7 @@ can be passed through the following way:
237
237
Proxy
238
238
^^^^^^^
239
239
240
-
Both httpx and aiohttp libraries use `urllib.request.getproxies` from
240
+
Both httpx2 and aiohttp libraries use `urllib.request.getproxies` from
241
241
environment variables. Before client initialization, you may set proxy (and
242
242
optional SSL_CERT_FILE) by setting the environment variables:
243
243
@@ -248,9 +248,9 @@ optional SSL_CERT_FILE) by setting the environment variables:
248
248
export SSL_CERT_FILE='client.pem'
249
249
250
250
251
-
If you need `socks5` proxy, httpx `supports <https://www.python-httpx.org/advanced/proxies/#socks>`_
252
-
`socks5` proxy if you pass it via args to httpx.Client(). You may install
253
-
`httpx[socks]` to use it. Then you can pass it through the following way:
251
+
If you need `socks5` proxy, httpx2 `supports <https://www.python-httpx.org/advanced/proxies/#socks>`_
252
+
`socks5` proxy if you pass it via args to httpx2.Client(). You may install
253
+
`httpx2[socks]` to use it. Then you can pass it through the following way:
0 commit comments