Skip to main content

tknOps LLM Analytics SDK

The Python SDK for tknOps, an AI cost and usage analytics platform.

Features

  • Automatic Usage Tracking: Capture token usage and cost.
  • Privacy-First: Prompt and response content are NOT stored by default.
  • Cost Calculation: Built-in pricing registry for common models (OpenAI, Anthropic).
  • Environment Tagging: Tag events as prod, dev, or staging.
  • Framework Support: Automatic extraction for OpenAI and LangChain response objects.

Installation

pip install tknops-llm

Usage

Initialization

from tknops_llm.client import AIAnalytics

client = AIAnalytics(
    api_key="your_api_key_here", # Get your API Key from the tknOps Dashboard
    environment="prod", # Optional: "prod", "dev", "staging". Default: "prod"
    collect_content=False # Optional: Set to True to collect prompt/response text. Default: False
)

1. Automatic Tracking (OpenAI / LangChain)

Use track_response to automatically extract metrics and calculate costs from response objects.

from langchain_openai import ChatOpenAI

llm = ChatOpenAI(model="gpt-4o", ...)
response = llm.invoke("Hello world!")

# Automatically extracts tokens and calculates cost based on model name
client.track_response(
    response=response,
    response_type="langchain", # "openai" or "langchain"
    user_id="user-123",        # Optional: Internal user ID
    feature="summarization",   # Optional: Feature name
    team="marketing",          # Optional: Team or Dept name
    agent="assistant_v1",      # Optional: Specific agent ID
    tags=["bot", "v2-test"]    # Optional: Custom tags for filtering
)

2. Manual Tracking

If you are using a custom model or provider, you can track events manually.

client.track(
    model="llama-3-8b",
    provider="together-ai",
    input_tokens=150,
    output_tokens=50,
    user_id="user-123",        # Optional: Internal user ID
    feature="adhoc-query",     # Optional: Feature name
    team="data-science",       # Optional: Team name
    agent="research-bot",      # Optional: Agent ID
    cost_usd=0.0002,           # Optional: Calculated by you
    latency_ms=450,            # Optional: Latency in ms
    tags=["custom-model"]      # Optional: Custom tags
)

3. Content Collection (Privacy)

By default, the SDK does not send the prompt or response text to the server. To enable content debugging:

# Initialize with collection enabled
client = AIAnalytics(..., collect_content=True)

# OR pass it explicitly in manual track (only if initialized with True)
client.track(..., prompt_text="My prompt", response_text="My response")

Tracking Parameters

The following parameters can be passed to tracking methods (track_response, track):

Parameter Type Description
user_id str Optional. The unique ID of the end-user in your system. Used for per-user cost analysis.
feature str Optional. The name of the feature or module where the AI is used (e.g., "summarization", "chat").
team str Optional. The team or department responsible for this usage (e.g., "marketing", "customer-success").
agent str Optional. The specific agent or bot identifier (e.g., "assistant_v1", "billing_bot").
environment str Optional. The deployment stage. Defaults to prod. Common values: stage, prod, dev.
tags List[str] Optional. A list of custom strings for granular filtering and grouping.

Configuration

Parameter Description Default
api_key Your Project API Key (obtained from tknOps dashboard) Required
environment Default environment tag for all events "prod"
collect_content If True, sends prompt/response text to the server for debugging. False

Metadata

Release files for tknops-llm 0.0.5

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

Source distribution (sdist)

Source distribution for tknops-llm 0.0.5
File Size Uploaded Provenance Actions
tknops_llm-0.0.5.tar.gz 5.5 kB Without provenance Details for tknops_llm-0.0.5.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for tknops-llm 0.0.5
File Interpreter ABI Platform Actions
tknops_llm-0.0.5-py3-none-any.whl Python 3 none any Details for tknops_llm-0.0.5-py3-none-any.whl

Total release size: 11.9 kB

Release files / tknops_llm-0.0.5.tar.gz

Download URL tknops_llm-0.0.5.tar.gz
Size 5.5 kB
Tags Source
SHA-256 checksum
How to use checksums
6a9c7c015b1c0ba5f05f529795ff90eb7da0c3d61745de2356b07ab428cd9659
BLAKE2b-256 checksum
How to use checksums
42a13fc8f2be301bc538164e4b6f2a2adb402ca9c829a69d26647e95dec24740
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.4

Release files / tknops_llm-0.0.5-py3-none-any.whl

Download URL tknops_llm-0.0.5-py3-none-any.whl
Size 6.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4c4ec49fbf93ce3ea000a93986238a3a063b94d0a45b279354dc65e6249f6c99
BLAKE2b-256 checksum
How to use checksums
57df545137f59a55feaf2ec142f44ee8f0ab84c0aeb8c88907499428c523400f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.4

Security for tknops-llm 0.0.5

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.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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