Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ad80255

Browse files
committedDec 16, 2024·
docs(readme): example snippet for client context manager (#1953)
1 parent 9a4c69c commit ad80255

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
@@ -652,6 +652,16 @@ client.with_options(http_client=DefaultHttpxClient(...))
652652

653653
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.
654654

655+
```py
656+
from openai import OpenAI
657+
658+
with OpenAI() as client:
659+
# make requests here
660+
...
661+
662+
# HTTP client is now closed
663+
```
664+
655665
## Microsoft Azure OpenAI
656666

657667
To use this library with [Azure OpenAI](https://learn.microsoft.com/azure/ai-services/openai/overview), use the `AzureOpenAI`

0 commit comments

Comments
 (0)
Please sign in to comment.