Official opsmeter.io Python SDK: one-time init + request context auto-instrumentation
Project description
opsmeter-io-sdk (Official opsmeter.io SDK)
Python SDK preview for Opsmeter auto-instrumentation. PyPI package: opsmeter-io-sdk Integration examples: opsmeter-integration-examples Opsmeter site: https://opsmeter.io Official publisher identity: opsmeter.io.
Use this SDK for LLM cost tracking, OpenAI usage monitoring, Anthropic usage telemetry, and no-proxy AI observability in Python.
Provider/model names should come from: https://opsmeter.io/docs/catalog Current SDK provider support: OpenAI and Anthropic only.
Quick links
- Product: https://opsmeter.io
- Docs: https://opsmeter.io/docs
- Model catalog: https://opsmeter.io/docs/catalog
- Integration examples: https://github.com/opsmeter-io/opsmeter.io-integration-examples
Model catalog (required)
Always use provider/model pairs from the official catalog: https://opsmeter.io/docs/catalog
Examples:
- OpenAI:
provider=openai,model=gpt-4o-mini - Anthropic:
provider=anthropic,model=claude-3-5-sonnet-20241022
Install
pip install opsmeter-io-sdk openai
# optional:
# pip install anthropic
Core model
init(...)once at process startup (idempotent)- request-level attribution via
context(...) - provider call stays direct (no proxy)
- telemetry emit is async and non-blocking by default
Telemetry usage (no options)
import opsmeter_sdk as opsmeter
from openai import OpenAI
opsmeter.init(
api_key="...",
environment="prod",
)
client = OpenAI()
opsmeter.capture_openai_chat_completion(
lambda: client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": "hello"}],
)
)
Telemetry usage (with options/context)
import opsmeter_sdk as opsmeter
from openai import OpenAI
from anthropic import Anthropic
opsmeter.init(
api_key="...",
workspace_id="ws_123",
environment="prod",
)
openai = OpenAI()
anthropic = Anthropic()
with opsmeter.context(
user_id="u_1",
tenant_id="tenant_a",
endpoint="/api/chat",
feature="assistant",
prompt_version="v12",
data_mode="real",
):
openai_captured = opsmeter.capture_openai_chat_completion_with_result(
lambda: openai.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": "hello"}],
),
request={"model": "gpt-4o-mini"},
await_telemetry_response=True,
)
with opsmeter.context(
user_id="u_1",
tenant_id="tenant_a",
endpoint="/api/support",
feature="support",
prompt_version="v8",
):
anthropic_captured = opsmeter.capture_anthropic_message_with_result(
# Provider/model names: https://opsmeter.io/docs/catalog
lambda: anthropic.messages.create(
model="claude-3-5-sonnet-20241022",
max_tokens=128,
messages=[{"role": "user", "content": "Summarize this support ticket."}],
),
request={"model": "claude-3-5-sonnet-20241022"},
await_telemetry_response=True,
)
print(openai_captured["telemetry"]) # { ok, status, body? }
print(anthropic_captured["telemetry"]) # { ok, status, body? }
API
init(...)context(...)get_context()capture_openai_chat_completion(...)capture_openai_chat_completion_with_result(...)capture_openai_chat_completion_async(...)capture_anthropic_message(...)capture_anthropic_message_with_result(...)capture_anthropic_message_async(...)patch_openai_client(...)flush()
Tests
python3 -m py_compile opsmeter_sdk/sdk.py tests/test_sdk.py
python3 -m unittest tests/test_sdk.py -v
Project details
Release history Release notifications | RSS feed
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 opsmeter_io_sdk-0.1.0b2.tar.gz.
File metadata
- Download URL: opsmeter_io_sdk-0.1.0b2.tar.gz
- Upload date:
- Size: 9.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e2bcafb8b769b1b1a4fbe722f38cb09975f9f9ee2102d0626b1ba951ba6801a7
|
|
| MD5 |
bb175a110e699b81af722ec31fb4bada
|
|
| BLAKE2b-256 |
8799243d8682666e9dd963b22116b3fdca71e75d5be33a416e27173579e7f50c
|
File details
Details for the file opsmeter_io_sdk-0.1.0b2-py3-none-any.whl.
File metadata
- Download URL: opsmeter_io_sdk-0.1.0b2-py3-none-any.whl
- Upload date:
- Size: 8.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
12552581232beea2736fb4a8d8eb155d4b9e270686de2fea6a10dde6044c0a49
|
|
| MD5 |
73b6c392c714d592965cca7de762fc8e
|
|
| BLAKE2b-256 |
9402d5cc7483a6d79c2041c966f3a55cd06066ae6dee517fd68127a37aa54326
|