Skip to main content

KairosRoute Python SDK — AI API broker with intelligent model routing

Project description

KairosRoute Python SDK

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

Install

pip install kairosroute

Quick Start

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

# 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

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.")

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kairosroute-0.1.0.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kairosroute-0.1.0-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file kairosroute-0.1.0.tar.gz.

File metadata

  • Download URL: kairosroute-0.1.0.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for kairosroute-0.1.0.tar.gz
Algorithm Hash digest
SHA256 90b69dab3007970181f7118b70f8226515e9f728a5e491bcca01d2f64b3d4316
MD5 36748fc432d5b4b92d436d7b675e492a
BLAKE2b-256 71c5194c1bc98ec4ba18d4d635a16eeebaad0ba9a2a1de82d236d74b9396afae

See more details on using hashes here.

File details

Details for the file kairosroute-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: kairosroute-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for kairosroute-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9cb2b69913d81f0e73b6c28078187c50c0e1e20f35bd23583f5eacce657e62c5
MD5 294a36deb12eeec47b9b5b449d9f8f3b
BLAKE2b-256 7220321a7adbb6d0cfce9fe9468497f433a960dcf5bd4663a95d271d5a1fb85b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page