Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

opsmeter-io-sdk (Official opsmeter.io SDK)

PyPI version license

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

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

Metadata

Release files for opsmeter-io-sdk 0.1.0b2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for opsmeter-io-sdk 0.1.0b2
File Size Uploaded Provenance
opsmeter_io_sdk-0.1.0b2.tar.gz 9.4 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for opsmeter-io-sdk 0.1.0b2
File Interpreter ABI Platform
opsmeter_io_sdk-0.1.0b2-py3-none-any.whl Python 3 none any Details

Total release size: 18.2 kB

Release files / opsmeter_io_sdk-0.1.0b2.tar.gz

Download URL opsmeter_io_sdk-0.1.0b2.tar.gz
Size 9.4 kB
Tags Source
SHA-256 checksum
How to use checksums
e2bcafb8b769b1b1a4fbe722f38cb09975f9f9ee2102d0626b1ba951ba6801a7
BLAKE2b-256 checksum
How to use checksums
8799243d8682666e9dd963b22116b3fdca71e75d5be33a416e27173579e7f50c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.14

Release files / opsmeter_io_sdk-0.1.0b2-py3-none-any.whl

Download URL opsmeter_io_sdk-0.1.0b2-py3-none-any.whl
Size 8.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
12552581232beea2736fb4a8d8eb155d4b9e270686de2fea6a10dde6044c0a49
BLAKE2b-256 checksum
How to use checksums
9402d5cc7483a6d79c2041c966f3a55cd06066ae6dee517fd68127a37aa54326
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.14

Security for opsmeter-io-sdk 0.1.0b2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page