Skip to main content

Caedral Python SDK

Official Python client for the Caedral API (v2.1.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",  # legacy alias; resolves to caedral-embed-e1-small-v1
    input="Caedral unifies frontier models behind one API.",
    input_type="query",
    dimensions=384,
    encoding_format="float",
)
print(len(result.data[0].embedding))  # 384

Supported embedding parameters: input_type (query | document), encoding_format (float | base64), and dimensions (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.1.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.1.0
File Size Uploaded
caedral-2.1.0.tar.gz 11.6 kB Details

Built distribution (wheel)

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

Total release size:26.4 kB

Release files / caedral-2.1.0.tar.gz

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

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

Download URL caedral-2.1.0-py3-none-any.whl
Size 14.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
861d029590eef98ec5a22e67ab4c7ae97d8a1532cdb45f23af0949d54edfbc02
BLAKE2b-256 checksum
How to use checksums
6ae4918bbf7949ed63089686f97e97a1dbf2fd6cbe10e9fc3b27203a49561a2c
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

This release

2.1.0 This release

2 release files

2.0.0

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