Skip to main content

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:

VariableRequiredDescription
CREDOAI_API_KEYYesYour API key from the Credo AI dashboard
CREDOAI_API_URLNoAPI endpoint URL. Defaults to https://api.credo.ai
CREDOAI_TENANTYesYour 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

  1. Log in to the Credo AI dashboard
  2. Navigate to Settings > API Keys
  3. Click Create API Key
  4. 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

Next Steps