Skip to content

Commit ceff94d

Browse files
docs(readme): example snippet for client context manager (#1953)
1 parent 06cac42 commit ceff94d

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

README.md

+10
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,16 @@ client.with_options(http_client=DefaultHttpxClient(...))
496496

497497
By default the library closes underlying HTTP connections whenever the client is [garbage collected](https://docs.python.org/3/reference/datamodel.html#object.__del__). You can manually close the client using the `.close()` method if desired, or with a context manager that closes when exiting.
498498

499+
```py
500+
from openai import OpenAI
501+
502+
with OpenAI() as client:
503+
# make requests here
504+
...
505+
506+
# HTTP client is now closed
507+
```
508+
499509
## Versioning
500510

501511
This package generally follows [SemVer](https://semver.org/spec/v2.0.0.html) conventions, though certain backwards-incompatible changes may be released as minor versions:

0 commit comments

Comments
 (0)