Skip to main content

Caedral Python SDK

Official Python client for the Caedral API. 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",
    input="Caedral unifies frontier models behind one API.",
)
print(len(result.data[0].embedding))

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 1.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 1.0.0
File Size Uploaded
caedral-1.0.0.tar.gz 10.4 kB Details

Built distribution (wheel)

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

Total release size: 24.6 kB

Release files / caedral-1.0.0.tar.gz

Download URL caedral-1.0.0.tar.gz
Size 10.4 kB
Tags Source
SHA-256 checksum
How to use checksums
9b5367f59c4fb4e4c9a3559ad956af2a065b8036c4e0e9ab10fcbdae1b0c9e93
BLAKE2b-256 checksum
How to use checksums
b6f0a610d8ac9ab9659828781d80b43c0f50b67617c8ca9dad526164e59e2ed5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

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

Download URL caedral-1.0.0-py3-none-any.whl
Size 14.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
42e877edd9abf69cde1e0d92c0d99e558336f29c14f1056efdcc0005e806cbff
BLAKE2b-256 checksum
How to use checksums
0a6eb85700c41c56879d94cf2497bf716f633369a53e8753f907755838b77a39
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release history Release notifications | RSS feed

2.1.0

2 release files

2.0.0

2 release files

This release

1.0.0 This release

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