Skip to main content

Official Python client for the Caedral API

Project description

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

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

caedral-0.1.0.tar.gz (10.4 kB view details)

Uploaded Source

Built Distribution

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

caedral-0.1.0-py3-none-any.whl (14.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for caedral-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d0ddf84842c8cc4898ffab22698f84ad8efb9e918ccfe15ef4507c42cdf0b926
MD5 c73decc5f90c4274f7f94a9a6b9fd3be
BLAKE2b-256 72c8d8561e0f24b474e30dd1e0a1b8e7aa06d3363685e01c97a93e256624f4f1

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for caedral-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 091617c892e99293c9037ab296dd6ede03c81798a1c668f9d88ce3630dec4776
MD5 6109aae5a7aea89340daf09bdc29a3b1
BLAKE2b-256 1af0ed5c467a310fe7f489e2c5e8a8d4e0393d02fdc745a2165bad19d79de920

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