> ## Documentation Index
> Fetch the complete documentation index at: https://docs.baytos.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Client Configuration

> Configure the Claro Python client for optimal performance

# Client Configuration

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

## Basic Initialization

```python theme={null}
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:

```python theme={null}
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:

```python theme={null}
# Production (default)
client = BaytClient(api_key="...")
# Uses: https://api.baytos.ai
```

<Note>
  **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:

  ```python theme={null}
  client = BaytClient(
      api_key="...",
      base_url="https://bayt.yourcompany.com"
  )
  ```

  Contact [support@baytos.ai](mailto:support@baytos.ai) to learn more about self-hosting options.
</Note>

### Retries and Timeouts

Configure retry behavior for resilient applications:

```python theme={null}
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)
)
```

<Note>
  The SDK uses exponential backoff: `retry_delay * (2 ** attempt)`. With `retry_delay=1.0`, retries occur at 1s, 2s, 4s, etc.
</Note>

### 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)**

```python theme={null}
# 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:

```python theme={null}
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

<Tip>
  Reuse the same `BaytClient` instance across your application for optimal performance.
</Tip>

## Custom Headers

Add custom headers to all requests:

```python theme={null}
client = BaytClient(
    api_key="...",
    headers={
        "X-App-Version": "1.2.3",
        "X-Environment": "production"
    }
)
```

## Proxy Configuration

Configure HTTP/HTTPS proxies:

```python theme={null}
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:pass@proxy.example.com:8080",
        "https": "https://user:pass@proxy.example.com:8443"
    }
)
```

## SSL/TLS Configuration

### Verify SSL Certificates

```python theme={null}
# 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"
)
```

<Warning>
  Disabling SSL verification exposes you to man-in-the-middle attacks. Only use in controlled development environments.
</Warning>

## User Agent

Customize the User-Agent header:

```python theme={null}
client = BaytClient(
    api_key="...",
    user_agent="MyApp/1.0 (contact@example.com)"
)
```

## Production Configuration Example

Complete production-ready configuration:

```python theme={null}
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

<AccordionGroup>
  <Accordion title="Reuse Client Instances" icon="recycle">
    Create one client instance and reuse it across your application:

    ```python theme={null}
    # ✅ 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")
    ```

    ```python theme={null}
    # ❌ Bad: Multiple instances
    def get_support_prompt():
        client = BaytClient(api_key=os.getenv("BAYT_API_KEY"))
        return client.get_prompt("@workspace/support:v1")
    ```
  </Accordion>

  <Accordion title="Set Appropriate Timeouts" icon="clock">
    Choose timeouts based on your use case:

    * **Interactive applications**: 5-10 seconds
    * **Background jobs**: 30-60 seconds
    * **Batch processing**: 60-120 seconds

    ```python theme={null}
    # Interactive
    client = BaytClient(api_key="...", timeout=10)

    # Background processing
    client = BaytClient(api_key="...", timeout=60)
    ```
  </Accordion>

  <Accordion title="Environment-Specific Configuration" icon="layer-group">
    Use different configurations per environment:

    ```python theme={null}
    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
        )
    ```
  </Accordion>
</AccordionGroup>

## Next Steps

<CardGroup cols={2}>
  <Card title="Working with Prompts" icon="sparkles" href="/sdk/python/prompts">
    Learn how to fetch and use prompts
  </Card>

  <Card title="Error Handling" icon="shield" href="/sdk/python/error-handling">
    Handle errors and retries gracefully
  </Card>

  <Card title="Advanced Features" icon="rocket" href="/sdk/python/advanced">
    Explore rate limiting, pooling, and performance optimization
  </Card>

  <Card title="API Reference" icon="book" href="/sdk/python/api-reference">
    Complete API documentation
  </Card>
</CardGroup>
