Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 5 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,37 +250,11 @@ client = genai.Client(
)
```

### HTTP client option: httpx2

By default, the SDK uses `httpx` for its HTTP transport. You can opt in to
[`httpx2`](https://github.com/pydantic/httpx2) by installing `google-genai[httpx2]`
and setting the `GOOGLE_GENAI_HTTP_CLIENT` environment variable:

```bash
export GOOGLE_GENAI_HTTP_CLIENT=httpx2
```

Alternatively, you can directly inject an `httpx2.Client` or `httpx2.AsyncClient`
via `HttpOptions`:

```python
import httpx2
from google import genai
from google.genai import types

client = genai.Client(
http_options=types.HttpOptions(
httpx_client=httpx2.Client(),
httpx_async_client=httpx2.AsyncClient(),
)
)
```

### Faster async client option: Aiohttp

By default we use httpx for both sync and async client implementations. In order
By default we use httpx2 for both sync and async client implementations. In order
to have faster performance, you may install `google-genai[aiohttp]`. In Gen AI
SDK we configure `trust_env=True` to match with the default behavior of httpx.
SDK we configure `trust_env=True` to match with the default behavior of httpx2.
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
through the following way:

Expand All @@ -295,7 +269,7 @@ client=Client(..., http_options=http_options)

### Proxy

Both httpx and aiohttp libraries use `urllib.request.getproxies` from
Both httpx2 and aiohttp libraries use `urllib.request.getproxies` from
environment variables. Before client initialization, you may set proxy (and
optional `SSL_CERT_FILE`) by setting the environment variables:

Expand All @@ -304,8 +278,8 @@ export HTTPS_PROXY='http://username:password@proxy_uri:port'
export SSL_CERT_FILE='client.pem'
```

If you need `socks5` proxy, httpx [supports](https://www.python-httpx.org/advanced/proxies/#socks) `socks5` proxy if you pass it via
args to `httpx.Client()`. You may install `httpx[socks]` to use it.
If you need `socks5` proxy, httpx2 [supports](https://www.python-httpx.org/advanced/proxies/#socks) `socks5` proxy if you pass it via
args to `httpx2.Client()`. You may install `httpx2[socks]` to use it.
Then, you can pass it through the following way:

```python
Expand Down
12 changes: 6 additions & 6 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,9 @@ To set the API version to `v1alpha` for the Gemini Developer API:
Faster async client option: Aiohttp
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

By default we use httpx for both sync and async client implementations. In order
By default we use httpx2 for both sync and async client implementations. In order
to have faster performance, you may install `google-genai[aiohttp]`. In Gen AI
SDK we configure `trust_env=True` to match with the default behavior of httpx.
SDK we configure `trust_env=True` to match with the default behavior of httpx2.
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 through the following way:
Expand All @@ -237,7 +237,7 @@ can be passed through the following way:
Proxy
^^^^^^^

Both httpx and aiohttp libraries use `urllib.request.getproxies` from
Both httpx2 and aiohttp libraries use `urllib.request.getproxies` from
environment variables. Before client initialization, you may set proxy (and
optional SSL_CERT_FILE) by setting the environment variables:

Expand All @@ -248,9 +248,9 @@ optional SSL_CERT_FILE) by setting the environment variables:
export SSL_CERT_FILE='client.pem'


If you need `socks5` proxy, httpx `supports <https://www.python-httpx.org/advanced/proxies/#socks>`_
`socks5` proxy if you pass it via args to httpx.Client(). You may install
`httpx[socks]` to use it. Then you can pass it through the following way:
If you need `socks5` proxy, httpx2 `supports <https://www.python-httpx.org/advanced/proxies/#socks>`_
`socks5` proxy if you pass it via args to httpx2.Client(). You may install
`httpx2[socks]` to use it. Then you can pass it through the following way:

.. code:: python

Expand Down
Loading
Loading