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
Required environment variables:
| Variable | Required | Purpose |
|---|---|---|
CLOPTIMA_LLM_OBSERVABILITY_INGEST_URL |
Yes | HTTPS endpoint for SDK event ingestion |
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_ENVIRONMENT |
Yes | Deployment environment such as dev, staging, or prod |
CLOPTIMA_LLM_OBSERVABILITY_TEAM_ID |
No | Team or ownership group |
CLOPTIMA_LLM_OBSERVABILITY_ENABLED |
No | Explicitly enable or disable the SDK |
CLOPTIMA_LLM_OBSERVABILITY_DELIVERY_MODE |
No | cloptima_http, otlp_http, or dual |
CLOPTIMA_LLM_OBSERVABILITY_OTLP_URL |
No | Custom OTLP endpoint |
CLOPTIMA_LLM_OBSERVABILITY_OTLP_SERVICE_NAME |
No | OTLP service name |
CLOPTIMA_LLM_OBSERVABILITY_OTLP_SERVICE_VERSION |
No | OTLP service version |
The SDK sends bearer-authenticated HTTPS requests to the configured Cloptima ingest endpoint.
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 the boundary helper when you already know the provider, model, and feature at the call site.
OTLP mode
The SDK supports three delivery modes:
cloptima_httpotlp_httpdual
Use otlp_http or dual when you want OpenTelemetry-compatible output in addition to, or instead of, direct Cloptima delivery.
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 boundary instrumentation
- Anthropic boundary instrumentation
- Gemini boundary instrumentation
- custom wrapper instrumentation
- httpx transport instrumentation
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
CLOPTIMA_LLM_OBSERVABILITY_INGEST_URL - verify the API key is valid for SDK event ingestion
- check
client.is_enabled() - 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.0.tar.gz.
File metadata
- Download URL: cloptima_llm_observability-0.1.0.tar.gz
- Upload date:
- Size: 38.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b38302f982d092b1415a83e166f72671f953e13fb348027adfea2ea9a40618db
|
|
| MD5 |
1839c384070713e1776dff39f427e88f
|
|
| BLAKE2b-256 |
d1a619c28f57c91fe24f5831cd0a7c7538e62562c01bf404b8dd45d986abcba8
|
Provenance
The following attestation bundles were made for cloptima_llm_observability-0.1.0.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.0.tar.gz -
Subject digest:
b38302f982d092b1415a83e166f72671f953e13fb348027adfea2ea9a40618db - Sigstore transparency entry: 1810317747
- Sigstore integration time:
-
Permalink:
cloptima/cloptima-llm-observability-python@4a3319d09d6322b15fd96ea2b381942cf8dc4d70 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/cloptima
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@4a3319d09d6322b15fd96ea2b381942cf8dc4d70 -
Trigger Event:
push
-
Statement type:
File details
Details for the file cloptima_llm_observability-0.1.0-py3-none-any.whl.
File metadata
- Download URL: cloptima_llm_observability-0.1.0-py3-none-any.whl
- Upload date:
- Size: 24.3 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 |
5fabb5bc8fe7c7708b1044bf5fbc42f4a3e2c5865d5b1839b25df57907aad060
|
|
| MD5 |
f9f77a5c487ed84a43d011e2667b4c28
|
|
| BLAKE2b-256 |
66845aaa540f8bc587e339d7bcbc3c8aaa16e92837fe9c64e7e093c2492ea939
|
Provenance
The following attestation bundles were made for cloptima_llm_observability-0.1.0-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.0-py3-none-any.whl -
Subject digest:
5fabb5bc8fe7c7708b1044bf5fbc42f4a3e2c5865d5b1839b25df57907aad060 - Sigstore transparency entry: 1810317796
- Sigstore integration time:
-
Permalink:
cloptima/cloptima-llm-observability-python@4a3319d09d6322b15fd96ea2b381942cf8dc4d70 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/cloptima
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@4a3319d09d6322b15fd96ea2b381942cf8dc4d70 -
Trigger Event:
push
-
Statement type: