# KairosRoute Python SDK

Drop-in replacement for the OpenAI Python client with intelligent model routing and cost optimization.

## Install

```bash
pip install kairosroute
```

## Quick Start

```python
from kairosroute import KairosRoute

client = KairosRoute(api_key="kr_live_...")

# Chat completions (same API as OpenAI)
response = client.chat.completions.create(
    model="kr-auto",  # auto-routes to cheapest model meeting quality threshold
    messages=[{"role": "user", "content": "Explain quantum computing in one sentence"}],
)
print(response["choices"][0]["message"]["content"])

# Embeddings
embeddings = client.embeddings.create(
    input="Hello world",
    model="kr-auto-embed",
)
print(f"Dimensions: {len(embeddings['data'][0]['embedding'])}")

# Streaming
for chunk in client.chat.completions.create(
    model="kr-auto",
    messages=[{"role": "user", "content": "Write a haiku"}],
    stream=True,
):
    if chunk.get("choices"):
        delta = chunk["choices"][0].get("delta", {})
        print(delta.get("content", ""), end="", flush=True)
```

## Migration from OpenAI

```python
# Before
from openai import OpenAI
client = OpenAI(api_key="sk-...")

# After
from kairosroute import KairosRoute
client = KairosRoute(api_key="kr_live_...")

# Everything else stays the same
```

## Error Handling

```python
from kairosroute import KairosRoute, RateLimitError, BudgetExceededError

client = KairosRoute(api_key="kr_live_...")

try:
    response = client.chat.completions.create(
        model="kr-auto",
        messages=[{"role": "user", "content": "Hello"}],
    )
except RateLimitError as e:
    print(f"Rate limited. Retry after {e.retry_after}s")
except BudgetExceededError:
    print("Daily budget exceeded. Upgrade to Pro.")
```
