Client Configuration
- Python
- TypeScript
The Python SDK provides two client types: synchronous (CredoAI) and asynchronous (AsyncCredoAI). Choose based on your application's needs.
The TypeScript SDK provides a single async client created via createCredoAIClient(). All methods return promises.
Creating a Client
- Python
- TypeScript
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)
import { createCredoAIClient } from '@credo-ai/sdk';
// Initialize with environment variables (recommended)
const client = createCredoAIClient('your-tenant');
// Or with explicit configuration
const client = createCredoAIClient('your-tenant', {
apiKey: 'your-api-key',
baseURL: 'https://api.credo.ai',
});
// Use the client
const { data, error } = await client.useCases.list();
if (!error) {
for (const uc of data.items) {
console.log(uc.name);
}
}
Async Client (Python)
- Python
- TypeScript
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()
The TypeScript client is async by default — all methods return promises. No context manager or manual cleanup is needed:
import { createCredoAIClient } from '@credo-ai/sdk';
const client = createCredoAIClient('your-tenant');
// All methods are async
const { data, error } = await client.useCases.list();
if (!error) {
for (const uc of data.items) {
console.log(uc.name);
}
}
When to Use Each Client
| Use Case | Python | TypeScript |
|---|---|---|
| Scripts and CLI tools | CredoAI (sync) | createCredoAIClient() |
| Jupyter notebooks | CredoAI (sync) | — |
| FastAPI / async web servers | AsyncCredoAI (async) | — |
| Express / Node.js servers | — | createCredoAIClient() |
| Concurrent API calls | AsyncCredoAI (async) | createCredoAIClient() |
| Django / Flask | CredoAI (sync) | — |
Client Options
- Python
- TypeScript
| 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) |
The first argument to createCredoAIClient() is the tenant (falls back to CREDOAI_TENANT env var). The second is an options object:
| Option | Type | Description |
|---|---|---|
apiKey | string | API key (defaults to CREDOAI_API_KEY env var) |
baseURL | string | API base URL (defaults to CREDOAI_API_URL env var) |
token | string | Pre-exchanged bearer token (takes precedence over apiKey) |
Accessing Resources
- Python
- TypeScript
# 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="...")
const client = createCredoAIClient('your-tenant');
// All methods are async and return { data, error }
const useCases = await client.useCases.list();
const model = await client.models.create({ name: 'My Model' });
const vendor = await client.vendors.get('vendor-id');
Next Steps
- Follow the quickstart
- Learn about async operations