Skip to main content

Client Configuration

The BaytClient class provides flexible configuration options for timeouts, retries, connection pooling, and more.

Basic Initialization

Configuration Options

API Key

The API key is required and can be provided in several ways:

Base URL

The SDK uses https://api.baytos.ai by default:
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:
Contact support@baytos.ai to learn more about self-hosting options.

Retries and Timeouts

Configure retry behavior for resilient applications:
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)

Connection Pooling

The SDK uses requests.Session for automatic connection pooling:
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.

Custom Headers

Add custom headers to all requests:

Proxy Configuration

Configure HTTP/HTTPS proxies:

SSL/TLS Configuration

Verify SSL Certificates

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:

Configuration Best Practices

Create one client instance and reuse it across your application:
Choose timeouts based on your use case:
  • Interactive applications: 5-10 seconds
  • Background jobs: 30-60 seconds
  • Batch processing: 60-120 seconds
Use different configurations per environment:

Next Steps

Working with Prompts

Learn how to fetch and use prompts

Error Handling

Handle errors and retries gracefully

Advanced Features

Explore rate limiting, pooling, and performance optimization

API Reference

Complete API documentation