Client Lifecycle
The SDK manages HTTP resources for you, but you still need to close the client when you are done.
Recommended Pattern
from touai import TouAI
with TouAI() as client:
results = client.context_hub.search("quarterly revenue")
print(results.total_results)When used as a context manager, the underlying HTTP connections are released automatically.
Manual Lifecycle
from touai import TouAI
client = TouAI()
try:
results = client.context_hub.search("quarterly revenue")
print(results.total_results)
finally:
client.close()When to Choose Each Style
| Pattern | Best For |
|---|---|
| Context manager | scripts, CLIs, short-lived jobs |
Manual close() | long-lived services with explicit lifecycle management |
If you create a client inside helper functions or background jobs, prefer the context manager form to avoid leaking network resources.