Skip to main content

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 CaseRecommended Client
Scripts and CLI toolsCredoAI (sync)
Jupyter notebooksCredoAI (sync)
FastAPI / async web serversAsyncCredoAI (async)
Concurrent API callsAsyncCredoAI (async)
Django / FlaskCredoAI (sync)

Client Options

Both clients accept the same configuration options:

OptionTypeDescription
api_keystrAPI key (defaults to CREDOAI_API_KEY env var)
base_urlstrAPI base URL (defaults to CREDOAI_API_URL env var)
tenantstrTenant 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