LLM usage telemetry SDK for Cloptima reporting, attribution, and analytics
Project description
Cloptima LLM Observability Python SDK
Capture LLM usage telemetry from your application and send it to Cloptima for cost reporting, attribution, and analytics.
Use this SDK when you want visibility into LLM usage without replacing your existing provider clients, retry policies, authentication, or application-level security controls.
Install
pip install cloptima-llm-observability
If you want to use the httpx transport helpers, install the optional extra:
pip install "cloptima-llm-observability[httpx]"
Configuration
Common environment variables:
| Variable | Required | Purpose |
|---|---|---|
CLOPTIMA_LLM_OBSERVABILITY_API_KEY |
Yes | Cloptima API key for telemetry writes |
CLOPTIMA_LLM_OBSERVABILITY_APP_ID |
Yes | Application or service identifier |
CLOPTIMA_LLM_OBSERVABILITY_ENABLED |
No | Explicitly enable or disable the SDK |
Recommended optional environment variables:
| Variable | Purpose |
|---|---|
CLOPTIMA_LLM_OBSERVABILITY_ENVIRONMENT |
Deployment environment such as dev, staging, or prod. Defaults to production, so set this explicitly when testing outside production. |
CLOPTIMA_LLM_OBSERVABILITY_TEAM_ID |
Team or ownership group |
The SDK sends bearer-authenticated HTTPS requests to https://api.cloptima.ai/v1/ai/integrations/sdk/events by default.
Quick start
Use observe_call(...) at the point where your application already invokes an LLM provider or an internal AI helper.
from cloptima_llm_observability import (
extract_openai_usage,
init_from_env,
)
cloptima = init_from_env()
result = cloptima.observe_call(
provider="openai",
model="gpt-4.1-mini",
call=lambda: summary_service.generate(prompt),
extract_usage=extract_openai_usage,
feature_id="summaries",
workflow_id="support-agent",
team_id="customer-support",
fire_and_forget=False,
)
This integration style works well because it:
- keeps your existing provider integration intact
- captures the most accurate model and feature context
- avoids SDK-specific coupling throughout your codebase
- works well with existing wrappers and shared AI services
Async and streaming calls
If your application already uses async calls or streaming responses, use the matching helpers:
result = await cloptima.observe_async_call(
provider="anthropic",
model="claude-3-5-sonnet",
call=lambda: assistant_client.reply(messages),
feature_id="chat_reply",
)
async for chunk in cloptima.observe_async_stream_call(
provider="openai",
model="gpt-4.1-mini",
call=lambda: stream_client.stream(prompt),
feature_id="live_answer",
):
print(chunk)
Shared transport integration
If your application centralizes outbound LLM calls behind a shared httpx transport, instrument that boundary instead:
import httpx
from cloptima_llm_observability import init_from_env, instrument_httpx_transport
cloptima = init_from_env()
transport = instrument_httpx_transport(
httpx.HTTPTransport(),
cloptima=cloptima,
provider="openai",
model="gpt-4o-mini",
fire_and_forget=False,
)
client = httpx.Client(transport=transport)
This is useful for broad coverage, but it has less application context than observe_call(...). Prefer observe_call(...) when you already know the provider, model, and feature at the call site.
OTLP mode
The SDK supports two delivery modes:
cloptima_httpotlp_http
Use otlp_http when you want the SDK to send OpenTelemetry-compatible payloads to Cloptima's OTLP-compatible receiver instead of the standard SDK telemetry endpoint.
otlp_http is still a Cloptima delivery mode. The SDK keeps the OTLP route fixed and only lets you override the Cloptima API domain or environment.
Advanced configuration:
CLOPTIMA_LLM_OBSERVABILITY_DELIVERY_MODEselectscloptima_httporotlp_httpCLOPTIMA_LLM_OBSERVABILITY_API_BASE_URLoverrides the Cloptima API domain while the SDK keeps the ingest routes fixedCLOPTIMA_LLM_OBSERVABILITY_OTLP_SERVICE_NAMEandCLOPTIMA_LLM_OBSERVABILITY_OTLP_SERVICE_VERSIONcustomize OTLP service metadata
Attribution fields
The most useful fields for reporting and ownership are:
app_idenvironmentteam_idfeature_idworkflow_idcost_centerbusiness_unittenant_idcustomer_segmentcloud_account_idcluster_idrepository_id
You can pass them through default_attribution, or directly on observe_call(...) / observe_stream_call(...).
Metadata controls
Use metadata_policy to control what custom metadata is retained:
metadata_onlyallowlisted_metadatastrict_finopsdebug_observability
Sensitive-looking keys such as prompts, messages, credentials, and secrets are treated conservatively by default.
Validation helpers
These helpers are useful when you want to inspect payloads locally before sending traffic to Cloptima:
preview_event_payload(...)preview_batch_payload(...)preview_otlp_request(...)validate_payload(...)
They return payload previews in memory and do not send network traffic.
Examples
See the examples/ directory for:
- OpenAI call-site instrumentation
- OpenTelemetry-compatible delivery to Cloptima
- Anthropic call-site instrumentation
- Gemini call-site instrumentation
- custom wrapper integration
- httpx transport integration
Public API
Stable core surface:
CloptimaLLMObservabilityinit_from_envdisabled_clientobserveobserve_callobserve_async_callobserve_streamobserve_stream_callrecordrecord_batchrecord_async- provider usage extractors
Additional helper surface:
instrument_httpx_clientinstrument_httpx_transportinstrument_openai_compatible_responseinstrument_openai_compatible_streamainstrument_openai_compatible_responseainstrument_openai_compatible_streaminstrument_fastapi_request_contextinstrument_flask_request_context
Troubleshooting
No telemetry arrives:
- verify the API key is valid for Cloptima telemetry ingestion
- check
client.is_enabled() - if you use advanced routing overrides, verify
CLOPTIMA_LLM_OBSERVABILITY_API_BASE_URLpoints at the intended Cloptima environment - inspect a sample event with
validate_payload(preview_event_payload(...))
Configuration behavior:
init_from_env()returns a disabled pass-through client when configuration is absent- if you explicitly enable the SDK with incomplete config, initialization stays non-blocking by default unless
strict=True
Payload contracts
- single event schema:
cloptima.llm.event.v1 - batch schema:
cloptima.llm.batch.v1
SDK envelopes also include sdk_delivery_stats for delivery monitoring.
Support
- Issues:
https://github.com/cloptima/cloptima-llm-observability-python/issues - Security: see
SECURITY.md - Product support:
hello@cloptima.ai
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cloptima_llm_observability-0.1.1.tar.gz.
File metadata
- Download URL: cloptima_llm_observability-0.1.1.tar.gz
- Upload date:
- Size: 38.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ed681a3d5bbf2ba0605ae3a4dfaef03e93fd8318b070995a366ffd5de78b8d6a
|
|
| MD5 |
70911e8c4c93ed2750c4f031335c0f1c
|
|
| BLAKE2b-256 |
adf49db69774586784fee118af02251579b6c7d7c7d2dbb9a3b7174bd4ddd4e4
|
Provenance
The following attestation bundles were made for cloptima_llm_observability-0.1.1.tar.gz:
Publisher:
release.yml on cloptima/cloptima-llm-observability-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cloptima_llm_observability-0.1.1.tar.gz -
Subject digest:
ed681a3d5bbf2ba0605ae3a4dfaef03e93fd8318b070995a366ffd5de78b8d6a - Sigstore transparency entry: 1810634556
- Sigstore integration time:
-
Permalink:
cloptima/cloptima-llm-observability-python@ff8be8540373f3e1b2c33905b9434ddadee7ae28 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/cloptima
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@ff8be8540373f3e1b2c33905b9434ddadee7ae28 -
Trigger Event:
push
-
Statement type:
File details
Details for the file cloptima_llm_observability-0.1.1-py3-none-any.whl.
File metadata
- Download URL: cloptima_llm_observability-0.1.1-py3-none-any.whl
- Upload date:
- Size: 24.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a0cf5ff07df311b44949b8e178fc1090a0b2df5de5bff1094f14f95268695bb2
|
|
| MD5 |
cf5c92e3530c0b103660dc0a48a54011
|
|
| BLAKE2b-256 |
ada4b72a5d933c3718d2203f892ecb3158ce0aca79b0011837ab4d05b00ec3c5
|
Provenance
The following attestation bundles were made for cloptima_llm_observability-0.1.1-py3-none-any.whl:
Publisher:
release.yml on cloptima/cloptima-llm-observability-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cloptima_llm_observability-0.1.1-py3-none-any.whl -
Subject digest:
a0cf5ff07df311b44949b8e178fc1090a0b2df5de5bff1094f14f95268695bb2 - Sigstore transparency entry: 1810634576
- Sigstore integration time:
-
Permalink:
cloptima/cloptima-llm-observability-python@ff8be8540373f3e1b2c33905b9434ddadee7ae28 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/cloptima
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@ff8be8540373f3e1b2c33905b9434ddadee7ae28 -
Trigger Event:
push
-
Statement type: