Getting Started
This guide will help you get up and running with the pycredoai SDK.
Installation
Install the SDK using pip:
pip install pycredoai
Requirements
- Python 3.8 or 3.9 or 3.10 or 3.11 or 3.12
- Dependencies:
- pydantic>=2.0.0
- httpx>=0.24.0
- attrs>=21.3.0
Authentication
The SDK requires an API key for authentication. You can obtain an API key from your account dashboard.
from credoai import Credoai
# Initialize with API key
client = Credoai(
base_url="https://api.credo.ai",
api_key="your-api-key"
)
Environment Variables
For security, consider using environment variables:
import os
from credoai import Credoai
client = Credoai(
base_url=os.getenv("CREDOAI_BASE_URL", "https://api.credo.ai"),
api_key=os.getenv("CREDOAI_API_KEY")
)
Basic Usage
Here are some basic examples to get you started:
Health Checks
# Check if the API is live
health_response = client.health.liveness()
print(f"API is live: {health_response}")
# Check readiness
readiness_response = client.health.readiness()
print(f"API is ready: {readiness_response}")
Working with Resources
System
# Metrics
response = client.system.metrics_metrics()
print(response)
# Ping
response = client.system.ping()
print(response)
Use_cases
# Create Use Case
from credoai.models import UseCaseCreate
data = UseCaseCreate(
# Add required fields here
)
response = client.use_cases.create(data=data)
print(response)
# List Use Cases
response = client.use_cases.list()
print(response)
Models
# Create Model
from credoai.models import ModelCreate
data = ModelCreate(
# Add required fields here
)
response = client.models.create(data=data)
print(response)
# List Models
response = client.models.list()
print(response)
Vendors
# Create Vendor
from credoai.models import VendorCreate
data = VendorCreate(
# Add required fields here
)
response = client.vendors.create(data=data)
print(response)
# List Vendors
response = client.vendors.list()
print(response)
Authentication
# Exchange API Key for Access Token
response = client.authentication.token()
print(response)
Health
# Liveness Probe
response = client.health.check_liveness()
print(response)
# Readiness Probe
response = client.health.check_readiness()
print(response)
Error Handling
The SDK provides structured error handling:
from credoai import Credoai
from credoai.errors import APIError, ValidationError
client = Credoai(
base_url="https://api.credo.ai",
api_key="your-api-key"
)
try:
response = client.some_resource.some_method()
print(response)
except ValidationError as e:
print(f"Validation error: {e}")
except APIError as e:
print(f"API error: {e.status_code} - {e.message}")
except Exception as e:
print(f"Unexpected error: {e}")
Configuration Options
The client can be configured with various options:
from credoai import
client = Credoai(
base_url="https://api.credo.ai",
api_key="your-api-key",
timeout=30.0, # Request timeout in seconds
max_retries=3, # Number of retries for failed requests
verify_ssl=True, # SSL certificate verification
)
Next Steps
- Explore the API Reference for detailed method documentation
- Check out Examples for common usage patterns
- View the complete Model Documentation for request/response schemas