From 83b96cab10b5259659ad1febc002c3a50109a8fa Mon Sep 17 00:00:00 2001 From: Stainless Bot Date: Mon, 16 Dec 2024 15:53:08 +0000 Subject: [PATCH] docs(readme): example snippet for client context manager --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index d26a031a98..d8eb0aebf5 100644 --- a/README.md +++ b/README.md @@ -496,6 +496,16 @@ client.with_options(http_client=DefaultHttpxClient(...)) 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. +```py +from openai import OpenAI + +with OpenAI() as client: + # make requests here + ... + +# HTTP client is now closed +``` + ## Versioning 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: