Client Configuration
The SDK provides two client types: synchronous (CredoAI) and asynchronous (AsyncCredoAI). Choose based on your application's needs.
Synchronous Client
The CredoAI client is ideal for scripts, CLI tools, and applications that don't require async/await:
from credoai import CredoAI
# Initialize with environment variables (recommended)
client = CredoAI()
# Or with explicit configuration
client = CredoAI(
api_key="your-api-key",
base_url="https://api.credo.ai",
tenant="your-tenant"
)
# Use the client
response = client.use_cases.list()
for uc in response.items:
print(uc.name)
Asynchronous Client
The AsyncCredoAI client is designed for async applications, web servers, and concurrent operations:
import asyncio
from credoai import AsyncCredoAI
async def main():
# Use as a context manager (recommended)
async with AsyncCredoAI() as client:
response = await client.use_cases.list()
for uc in response.items:
print(uc.name)
asyncio.run(main())
Async Context Manager
The async client should be used as a context manager to ensure proper cleanup:
async with AsyncCredoAI() as client:
# Client is properly initialized
await client.use_cases.list()
# Client is automatically closed
Manual Lifecycle Management
If you can't use a context manager:
client = AsyncCredoAI()
try:
await client.use_cases.list()
finally:
await client.close()
When to Use Each Client
| Use Case | Recommended Client |
|---|---|
| Scripts and CLI tools | CredoAI (sync) |
| Jupyter notebooks | CredoAI (sync) |
| FastAPI / async web servers | AsyncCredoAI (async) |
| Concurrent API calls | AsyncCredoAI (async) |
| Django / Flask | CredoAI (sync) |
Client Options
Both clients accept the same configuration options:
| Option | Type | Description |
|---|---|---|
api_key | str | API key (defaults to CREDOAI_API_KEY env var) |
base_url | str | API base URL (defaults to CREDOAI_API_URL env var) |
tenant | str | Tenant identifier (defaults to CREDOAI_TENANT env var) |
Accessing Resources
Both clients provide the same resource interface:
# Synchronous
client = CredoAI()
client.use_cases.list()
client.models.create(data=model_data)
client.vendors.get(vendor_id="...")
# Asynchronous
async with AsyncCredoAI() as client:
await client.use_cases.list()
await client.models.create(data=model_data)
await client.vendors.get(vendor_id="...")
Next Steps
- Follow the quickstart
- Learn about async operations