Client Configuration
The BaytClient class provides flexible configuration options for timeouts, retries, connection pooling, and more.
Basic Initialization
from baytos.claro import BaytClient
client = BaytClient( api_key = "your_api_key" )
Configuration Options
API Key
The API key is required and can be provided in several ways:
import os
from baytos.claro import BaytClient
# Method 1: Environment variable (recommended)
client = BaytClient( api_key = os.getenv( "BAYT_API_KEY" ))
# Method 2: Direct (not recommended for production)
client = BaytClient( api_key = "your_api_key_here" )
# Method 3: From config file
import json
with open ( 'config.json' ) as f:
config = json.load(f)
client = BaytClient( api_key = config[ 'bayt_api_key' ])
Base URL
The SDK uses https://api.baytos.ai by default:
# Production (default)
client = BaytClient( api_key = "..." )
# Uses: https://api.baytos.ai
Enterprise Self-Hosting: If you’re running a self-hosted instance of Bayt OS (available for enterprise customers), you can override the base_url parameter to point to your instance:client = BaytClient(
api_key = "..." ,
base_url = "https://bayt.yourcompany.com"
)
Contact [email protected] to learn more about self-hosting options.
Retries and Timeouts
Configure retry behavior for resilient applications:
client = BaytClient(
api_key = "..." ,
max_retries = 3 , # Number of retry attempts (default: 3)
timeout = 30 , # Request timeout in seconds (default: 30)
retry_delay = 1.0 # Initial retry delay in seconds (default: 1.0)
)
The SDK uses exponential backoff: retry_delay * (2 ** attempt). With retry_delay=1.0, retries occur at 1s, 2s, 4s, etc.
Retry Behavior
The SDK automatically retries on:
429 (Rate Limit) - Respects Retry-After header
5xx (Server Errors) - Uses exponential backoff
Network Errors - Connection timeouts, DNS failures
The SDK does NOT retry on:
4xx (Client Errors) - Except 429
Authentication Errors (401, 403)
Not Found (404)
# Aggressive retries for unreliable networks
client = BaytClient(
api_key = "..." ,
max_retries = 5 ,
timeout = 60
)
# Disable retries (fast-fail)
client = BaytClient(
api_key = "..." ,
max_retries = 0
)
Connection Pooling
The SDK uses requests.Session for automatic connection pooling:
client = BaytClient( api_key = "..." )
# Connection is established and pooled
prompt1 = client.get_prompt( "@workspace/p1:v1" )
# Connection is reused (faster)
prompt2 = client.get_prompt( "@workspace/p2:v1" )
prompt3 = client.get_prompt( "@workspace/p3:v1" )
Benefits:
Faster subsequent requests (no TCP handshake)
Lower latency
Reduced server load
Automatic keep-alive management
Reuse the same BaytClient instance across your application for optimal performance.
Add custom headers to all requests:
client = BaytClient(
api_key = "..." ,
headers = {
"X-App-Version" : "1.2.3" ,
"X-Environment" : "production"
}
)
Proxy Configuration
Configure HTTP/HTTPS proxies:
client = BaytClient(
api_key = "..." ,
proxies = {
"http" : "http://proxy.example.com:8080" ,
"https" : "https://proxy.example.com:8443"
}
)
# With authentication
client = BaytClient(
api_key = "..." ,
proxies = {
"http" : "http://user:[email protected] :8080" ,
"https" : "https://user:[email protected] :8443"
}
)
SSL/TLS Configuration
Verify SSL Certificates
# Enable SSL verification (default)
client = BaytClient( api_key = "..." , verify_ssl = True )
# Disable SSL verification (not recommended)
client = BaytClient( api_key = "..." , verify_ssl = False )
# Use custom CA bundle
client = BaytClient(
api_key = "..." ,
verify_ssl = "/path/to/ca-bundle.crt"
)
Disabling SSL verification exposes you to man-in-the-middle attacks. Only use in controlled development environments.
User Agent
Customize the User-Agent header:
Production Configuration Example
Complete production-ready configuration:
import os
from baytos.claro import BaytClient
client = BaytClient(
# Authentication
api_key = os.getenv( "BAYT_API_KEY" ),
# Performance
max_retries = 3 ,
timeout = 30 ,
retry_delay = 1.0 ,
# Monitoring
headers = {
"X-App-Version" : os.getenv( "APP_VERSION" , "unknown" ),
"X-Environment" : os.getenv( "ENVIRONMENT" , "production" ),
"X-Instance-ID" : os.getenv( "INSTANCE_ID" , "unknown" )
},
# Security
verify_ssl = True
)
Configuration Best Practices
Create one client instance and reuse it across your application: # ✅ Good: Single instance
client = BaytClient( api_key = os.getenv( "BAYT_API_KEY" ))
def get_support_prompt ():
return client.get_prompt( "@workspace/support:v1" )
def get_marketing_prompt ():
return client.get_prompt( "@workspace/marketing:v1" )
# ❌ Bad: Multiple instances
def get_support_prompt ():
client = BaytClient( api_key = os.getenv( "BAYT_API_KEY" ))
return client.get_prompt( "@workspace/support:v1" )
Choose timeouts based on your use case:
Interactive applications : 5-10 seconds
Background jobs : 30-60 seconds
Batch processing : 60-120 seconds
# Interactive
client = BaytClient( api_key = "..." , timeout = 10 )
# Background processing
client = BaytClient( api_key = "..." , timeout = 60 )
Environment-Specific Configuration
Use different configurations per environment: import os
ENV = os.getenv( "ENVIRONMENT" , "production" )
if ENV == "development" :
client = BaytClient(
api_key = os.getenv( "BAYT_API_KEY" ),
max_retries = 0 , # Fast-fail in dev
timeout = 10
)
else : # production
client = BaytClient(
api_key = os.getenv( "BAYT_API_KEY" ),
max_retries = 3 ,
timeout = 30
)
Next Steps