Finishing and Lifecycle
Finish the SDK lifecycle safely by closing the Adstract client in sync and async flows.
Why closing matters
Closing the client prevents leaking open HTTP connections and keeps service resource usage stable.
Closing the client
Use close() in synchronous runtimes:
- Python
from adstractai import Adstract
client = Adstract(api_key="your-api-key")
client.close()
Use the async close method in asynchronous runtimes:
- Python
import asyncio
from adstractai import Adstract
async def main() -> None:
client = Adstract(api_key="your-api-key")
await client.aclose()
asyncio.run(main())
Ownership note
- If you pass custom
httpxclients intoAdstract, your application owns those clients and should close them directly. - If
Adstractcreates internal clients, callingcloseoraclosehandles cleanup.
Next steps
- Continue to Important and Disclaimers.