Authentication
The SDK authenticates with the Credo AI platform using API keys. You can configure authentication via environment variables or by passing credentials directly to the client.
Environment Variables
The recommended approach is to set environment variables:
| Variable | Required | Description |
|---|---|---|
CREDOAI_API_KEY | Yes | Your API key from the Credo AI dashboard |
CREDOAI_API_URL | No | API endpoint URL. Defaults to https://api.credo.ai |
CREDOAI_TENANT | Yes | Your organization's tenant identifier |
Setting Environment Variables
In your shell:
export CREDOAI_API_KEY="your-api-key"
export CREDOAI_API_URL="https://api.credo.ai"
export CREDOAI_TENANT="your-tenant"
In a .env file:
CREDOAI_API_KEY=your-api-key
CREDOAI_API_URL=https://api.credo.ai
CREDOAI_TENANT=your-tenant
In Python:
import os
os.environ["CREDOAI_API_KEY"] = "your-api-key"
os.environ["CREDOAI_API_URL"] = "https://api.credo.ai"
os.environ["CREDOAI_TENANT"] = "your-tenant"
Explicit Configuration
You can also pass credentials directly to the client:
from credoai import CredoAI
client = CredoAI(
api_key="your-api-key",
base_url="https://api.credo.ai",
tenant="your-tenant"
)
warning
Avoid hardcoding credentials in your source code. Use environment variables or a secrets manager for production deployments.
Obtaining API Keys
- Log in to the Credo AI dashboard
- Navigate to Settings > API Keys
- Click Create API Key
- Copy the generated key and store it securely
Verifying Authentication
After configuring credentials, verify the connection:
from credoai import CredoAI
client = CredoAI()
# Test the connection
ping = client.system.ping()
print(f"Connection successful: {ping.message}")
Authentication Errors
If authentication fails, the SDK raises an AuthenticationError:
from credoai import CredoAI
from credoai.auth import AuthenticationError
try:
client = CredoAI()
client.system.ping()
except AuthenticationError as e:
print(f"Authentication failed: {e}")
Common causes:
- Invalid or expired API key
- Missing required environment variables
- Incorrect tenant identifier