Skip to main content

Caedral Python SDK

Official Python client for the Caedral API (v2.0.0). OpenAI-compatible request shapes — point your existing code at Caedral with minimal changes.

Installation

pip install caedral

Local development (editable install)

cd sdk-python
python -m venv .venv
source .venv/bin/activate          # Windows: .venv\Scripts\activate
pip install -e ".[dev]"

Quickstart

from caedral import Caedral

caedral = Caedral(
    api_key="cd_live_...",
    base_url="http://localhost:5001",  # local API gateway
)

completion = caedral.chat.completions.create(
    model="caedral-titan",
    messages=[{"role": "user", "content": "Hello!"}],
)

print(completion.choices[0].message["content"])
caedral.close()

Or use a context manager:

with Caedral(api_key="cd_live_...", base_url="http://localhost:5001") as caedral:
    usage = caedral.usage.get()
    print(usage.weeklyPool.remaining)

Production default base URL: https://api.caedral.com.

Configuration

Parameter Default Description
api_key Required. Your cd_live_... API key
base_url https://api.caedral.com API gateway base URL
max_retries 3 Retries for idempotent GET requests (exponential backoff)
timeout 120.0 Request timeout in seconds

Methods

caedral.chat.completions.create(...)

OpenAI-compatible chat completions.

Non-streaming:

response = caedral.chat.completions.create(
    model="caedral-olympus",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Explain quantum computing briefly."},
    ],
    temperature=0.7,
    max_tokens=500,
)

print(response.choices[0].message["content"])
print(response.usage.total_tokens if response.usage else None)

Streaming (generator):

stream = caedral.chat.completions.create(
    model="caedral-titan",
    messages=[{"role": "user", "content": "Write a haiku about code."}],
    stream=True,
)

for chunk in stream:
    delta = chunk.choices[0].delta.get("content")
    if delta:
        print(delta, end="", flush=True)
print()

Models: caedral-base, caedral-titan, caedral-olympus, caedral-primordial.

caedral.models.list()

models = caedral.models.list()
for model in models.data:
    print(model.id, model.name, model.pricing_tier)

caedral.usage.get()

usage = caedral.usage.get()
print("Pool remaining:", usage.weeklyPool.remaining)
print("Balance (cents):", usage.balanceCents)
print("Overage used:", usage.overage.usedCents)

caedral.embeddings.create(...)

result = caedral.embeddings.create(
    model="caedral-embed-e1-small-v1",
    input="query: Caedral unifies frontier models behind one API.",
    dimensions=384,
)
print(len(result.data[0].embedding))  # 384

caedral.images.generate(...)

image = caedral.images.generate(
    model="caedral-vision",
    prompt="A minimal geometric logo on a dark background",
)
print(image.data[0].url or "b64 payload returned")

caedral.audio.generate(...)

audio = caedral.audio.generate(
    model="caedral-voice",
    input="Welcome to Caedral.",
    voice="alloy",
)
print(audio.model)

caedral.rerank.create(...)

ranked = caedral.rerank.create(
    model="caedral-rerank",
    query="billing and subscriptions",
    documents=[
        "Caedral pricing tiers include Starter and Pro.",
        "The API gateway runs on port 5001 in local dev.",
    ],
    top_n=2,
)
for item in ranked.results:
    print(item.index, item.relevance_score)

Error handling

from caedral import Caedral, CaedralAPIError

try:
    caedral.chat.completions.create(
        model="caedral-base",
        messages=[{"role": "user", "content": "Hi"}],
    )
except CaedralAPIError as err:
    print(err.status_code, err.type, err.message)

Async client

AsyncCaedral is planned as a fast-follow. The synchronous client covers all endpoints today.

Integration tests

Requires a running local gateway (http://localhost:5001) and DATABASE_URL in the repo root .env (tests create a temporary API key automatically).

cd sdk-python
pip install -e ".[dev]"
pytest -v

Optional environment variables:

Variable Description
CAEDRAL_BASE_URL Gateway URL (default http://localhost:5001)
CAEDRAL_TEST_API_KEY Skip auto key creation and use an existing key

License

MIT

Release files for caedral 2.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for caedral 2.0.0
File Size Uploaded
caedral-2.0.0.tar.gz 11.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for caedral 2.0.0
File Interpreter ABI Platform
caedral-2.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 25.8 kB

Release files / caedral-2.0.0.tar.gz

Download URL caedral-2.0.0.tar.gz
Size 11.2 kB
Tags Source
SHA-256 checksum
How to use checksums
336415a639b521b802d93fd3cd3c761aa419c400f9b43f28bf85fd65bbeadf09
BLAKE2b-256 checksum
How to use checksums
adf04f8bfb194642d4a4d9b852127000cfba7b415a371eeb85d7d6c4d40b12c5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.6

Release files / caedral-2.0.0-py3-none-any.whl

Download URL caedral-2.0.0-py3-none-any.whl
Size 14.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ef6b8725246d14ca965a24a313761c0b1e99e0606104c1751438e2ac8fcddc61
BLAKE2b-256 checksum
How to use checksums
faf4179be8ecfba8db744f070401c051ff8964ba76d2f2a5be691316ffd77b39
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.6

Release history Release notifications | RSS feed

2.1.0

2 release files

This release

2.0.0 This release

2 release files

1.0.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page