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 4c8b628
Browse filesBrowse the repository at this point in the historyBrowse files
feat(client)!: 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 the default `httpx2` SSL context now uses the OS
certificate trust store (via `truststore` / `httpx2.create_ssl_context()`) when
`SSL_CERT_FILE` and `SSL_CERT_DIR` are not set. The `httpx2` extra is kept as an
empty no-op for backwards compatibility, and `httpx` is now an optional extra
(`google-genai[httpx]`).
Pinning the HTTP client backend via `GOOGLE_GENAI_HTTP_CLIENT`:
- To opt back into legacy `httpx`, install `google-genai[httpx]` and set
`GOOGLE_GENAI_HTTP_CLIENT=httpx` (raises `ImportError` if `httpx` is not
installed).
- Set `GOOGLE_GENAI_HTTP_CLIENT=httpx2` to explicitly require `httpx2` without
fallback (raises `ImportError` if `httpx2` is not installed).
- Leave `GOOGLE_GENAI_HTTP_CLIENT` unset (or `auto`) to use `httpx2` by default,
falling back to `httpx` if only `httpx` is installed.
#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