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 79d7785
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: README.md
+21-69Lines changed: 21 additions & 69 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@
5
5
6
6
The OpenAI Python library provides convenient access to the OpenAI REST API from any Python 3.10+
7
7
application. The library includes type definitions for all request params and response fields,
8
-
and offers both synchronous and asynchronous clients powered by [httpx](https://github.com/encode/httpx).
8
+
and offers both synchronous and asynchronous clients powered by [HTTPX2](https://httpx2.pydantic.dev/).
9
9
10
10
It is generated from our [OpenAPI specification](https://github.com/openai/openai-openapi) with [Stainless](https://stainlessapi.com/).
11
11
@@ -244,9 +244,7 @@ Functionality between the synchronous and asynchronous clients is otherwise iden
244
244
245
245
### With aiohttp
246
246
247
-
By default, the async client uses `httpx` for HTTP requests. However, for improved concurrency performance you may also use `aiohttp` as the HTTP backend.
248
-
249
-
The `aiohttp` backend requires Python 3.10 or later.
247
+
By default, the async client uses HTTPX2. For improved concurrency performance, you may also use `aiohttp` as the HTTPX2 transport.
250
248
251
249
You can enable this by installing `aiohttp`:
252
250
@@ -283,32 +281,9 @@ async def main() -> None:
283
281
asyncio.run(main())
284
282
```
285
283
286
-
### Experimental HTTPX2 support
287
-
288
-
To opt in to experimental HTTPX2 support, install the optional extra on Python 3.10 or later:
289
-
290
-
```sh
291
-
pip install 'openai[httpx2]'
292
-
```
293
-
294
-
```python
295
-
from openai import OpenAI, AsyncOpenAI, DefaultHttpx2Client, DefaultAsyncHttpx2Client
See [`examples/httpx2_client.py`](examples/httpx2_client.py) for a minimal runnable example.
284
+
### HTTPX2 migration
302
285
303
-
The module-level client can be configured in the same way:
304
-
305
-
```python
306
-
import openai
307
-
308
-
openai.http_client = openai.DefaultHttpx2Client()
309
-
```
310
-
311
-
Parsed API models are unchanged, but requests, raw and streaming responses, and transport-level exceptions may be HTTPX2 objects at runtime. Code that catches HTTPX exceptions or relies on HTTPX-specific mocks, transports, authentication, hooks, or instrumentation may need to be updated. Transport-facing type annotations may still describe HTTPX.
286
+
HTTPX2 is the default HTTP client. If you configure a custom HTTP client, transport, timeout, authentication handler, event hook, or request mock, see the [HTTPX2 migration guide](httpx2.md).
312
287
313
288
## Streaming responses
314
289
@@ -636,7 +611,7 @@ try:
636
611
)
637
612
except openai.APIConnectionError as e:
638
613
print("The server could not be reached")
639
-
print(e.__cause__) # an underlying Exception, likely raised within httpx.
614
+
print(e.__cause__) # an underlying Exception, likely raised within HTTPX2.
640
615
except openai.RateLimitError as e:
641
616
print("A 429 status code was received; we should back off a bit.")
By default requests time out after 10 minutes. You can configure this with a `timeout` option,
726
-
which accepts a float or an [`httpx.Timeout`](https://www.python-httpx.org/advanced/timeouts/#fine-tuning-the-configuration) object:
701
+
which accepts a float or an [`httpx2.Timeout`](https://httpx2.pydantic.dev/) object:
@@ -849,11 +825,11 @@ To make requests to undocumented endpoints, you can make requests using `client.
849
825
http verbs. Options on the client will be respected (such as retries) when making this request.
850
826
851
827
```py
852
-
importhttpx
828
+
importhttpx2
853
829
854
830
response = client.post(
855
831
"/foo",
856
-
cast_to=httpx.Response,
832
+
cast_to=httpx2.Response,
857
833
body={"my_param": True},
858
834
)
859
835
@@ -873,30 +849,26 @@ can also get all the extra fields on the Pydantic model as a dict with
873
849
874
850
### Configuring the HTTP client
875
851
876
-
You can directly override the [httpx client](https://www.python-httpx.org/api/#client) to customize it for your use case, including:
877
-
878
-
- Support for [proxies](https://www.python-httpx.org/advanced/proxies/)
You can override the [HTTPX2 client](https://httpx2.pydantic.dev/) to customize proxies, transports, authentication, event hooks, and other advanced HTTP behavior. See the [HTTPX2 migration guide](httpx2.md) when updating an existing custom client.
0 commit comments