Skip to main content

Kalmia Tracing SDK — automatic LLM call tracing for OpenAI and Anthropic

Project description

Kalmia SDK (Python)

Automatic LLM call tracing for OpenAI and Anthropic. Wrap your client once and every call — prompts, responses, tool calls, errors — is captured and sent to your Kalmia dashboard. Zero external dependencies.

Installation

pip install kalmia

Usage

Get your API key from the Kalmia dashboard, then initialize the logger once at startup and wrap your LLM client:

from kalmia import init_logger, wrap_anthropic
import anthropic

init_logger(
    project_name="my-agent",
    api_key="kal_live_your_api_key",  # required — or set KALMIA_API_KEY
)

client = wrap_anthropic(anthropic.Anthropic())
# use `client` exactly like the Anthropic SDK — traces are captured automatically

OpenAI works the same way:

from kalmia import init_logger, wrap_openai
import openai

init_logger(project_name="my-agent", api_key="kal_live_your_api_key")
client = wrap_openai(openai.OpenAI())

Configuration

Argument / env var Purpose
project_name (required) Groups traces under a project.
api_key / KALMIA_API_KEY Workspace API key. Without it, traces are rejected and dropped.
base_url / KALMIA_BASE_URL Where traces are sent. Defaults to the hosted Kalmia backend (https://www.kalmia.dev). Set this for local development or self-hosting.

Decorators and spans

Use @traced to capture custom steps, and current_span() to log inside them:

from kalmia import traced, current_span

@traced(name="run")
def run(message):
    current_span().log(input={"message": message})
    ...

Delivery reliability

Trace delivery is at-least-once with no silent loss:

  • Retry with backoff. Transient failures (transport errors, timeouts, 429, 5xx) are retried with bounded backoff. Permanent 4xx responses (400, 401, 413) are not retried.
  • Buffering. A trace that still fails after its retries is held in a bounded in-memory buffer and re-attempted on the next send, then once more at interpreter exit (atexit).
  • No silent loss. Every drop path — a non-retryable response, a full buffer evicting its oldest entry, a server-side rejection, or a trace still undelivered at exit — emits a warning naming the trace id, so a lost run is always visible in your logs.
  • Safe retries. The backend de-duplicates by trace id, so a retried delivery never creates a duplicate.

The buffer lives in memory, so a hard kill (SIGKILL, OOM) can still lose buffered traces — those are warned when the trace is first buffered. Durable on-disk buffering is planned. Delivery never raises into your application.

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

kalmia-0.2.0.tar.gz (21.1 kB view details)

Uploaded Source

Built Distribution

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

kalmia-0.2.0-py3-none-any.whl (13.2 kB view details)

Uploaded Python 3

File details

Details for the file kalmia-0.2.0.tar.gz.

File metadata

  • Download URL: kalmia-0.2.0.tar.gz
  • Upload date:
  • Size: 21.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.4

File hashes

Hashes for kalmia-0.2.0.tar.gz
Algorithm Hash digest
SHA256 bd843b02291fed7f3d20ec1c7d01469d7d866caa8a02fe90fd9ce8c29d810ee7
MD5 4f24a04e111ac98d404d6543ab6f75d5
BLAKE2b-256 0356dbe1fa0697101b6ebf3d0d11bdac15a44bf4107f58ef83a6008cfc15db65

See more details on using hashes here.

File details

Details for the file kalmia-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: kalmia-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 13.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.4

File hashes

Hashes for kalmia-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4f3eef15616440ff60f4c5c4a0b697b6792c4a0c618ae7df0728301333cc2ef0
MD5 607035da6a061d613b91e9dfe254e021
BLAKE2b-256 97f9881c46b706834f5d4c1815dc74684fb62abc056fd741a9f65b6a14aaa10c

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