Skip to main content

inferspect-sdk

Lightweight Python SDK for capturing LLM inference logs, tool executions, and application logs — with client-side PII redaction so sensitive data never leaves your process unredacted.

Auto-instruments raw OpenAI / Anthropic / Google Gemini clients, plus framework integrations for LangChain and LlamaIndex. Sync and async APIs. No telemetry vendor lock-in — point it at any HTTPS ingestion endpoint that accepts the wire format.

Install

# Core only (no framework deps pulled in)
pip install inferspect-sdk

# With your stack:
pip install "inferspect-sdk[openai]"
pip install "inferspect-sdk[anthropic]"
pip install "inferspect-sdk[google]"
pip install "inferspect-sdk[langchain]"
pip install "inferspect-sdk[llamaindex]"

# Everything
pip install "inferspect-sdk[all]"

Quickstart — raw OpenAI

import asyncio
from openai import AsyncOpenAI
from chatbot_sdk import InferenceLogger
from chatbot_sdk.integrations.openai import instrument

async def main():
    client = AsyncOpenAI()
    logger = InferenceLogger.from_env()   # reads CHATBOT_SDK_URL + CHATBOT_SDK_KEY
    instrument(client, logger=logger)     # ← one-line monkey-patch; idempotent

    async with logger:
        resp = await client.chat.completions.create(
            model="gpt-4o-mini",
            messages=[{"role": "user", "content": "Say hello"}],
        )
        print(resp.choices[0].message.content)
        # Every call is auto-traced — no per-call wrapping.

asyncio.run(main())

Set two env vars before running:

export CHATBOT_SDK_URL=https://your-ingestion-host/v1/logs
export CHATBOT_SDK_KEY=your-sdk-api-key

Quickstart — LangChain

from chatbot_sdk import InferenceLogger
from chatbot_sdk.integrations.langchain import SDKCallback

logger = InferenceLogger.from_env()
await logger.start()

callback = SDKCallback(sdk=logger)
result = await agent.ainvoke(
    {"messages": msgs},
    config={"callbacks": [callback]},   # every LLM + tool call inside is auto-traced
)

Quickstart — sync (Flask / Django / notebooks)

from chatbot_sdk import SyncInferenceLogger

logger = SyncInferenceLogger.from_env()
with logger:
    with logger.inference(provider="openai", model="gpt-4o-mini") as span:
        resp = client.chat.completions.create(...)
        span.set_response(resp)

What gets logged

Per inference: provider, model, prompt_tokens, completion_tokens, latency_ms, ttft_ms (streaming), status (ok/error/cancelled/timeout), finish_reason, tool_calls_summary, input_preview, output_preview, plus per-request conversation_id / session_id / user_id if set via logger.context(...).

Per tool call: tool_name, args_preview, result_preview, latency_ms, status + error fields, linked to parent inference via parent_inference_request_id.

PII redaction

Runs inside your process before any event leaves over the network. Default recognizers: email, phone (E.164 + NA), credit card (Luhn-validated), US SSN, IBAN, IPv4, AWS access keys. Configurable via InferenceLogger(pii_redact=True, pii_recognizers=[...]).

Zero third-party deps for redaction (pure regex). Server-side PII can run as defense-in-depth if your ingestion service supports it.

Provider matrix

Library Integration Pattern
openai (AsyncOpenAI) chatbot_sdk.integrations.openai.instrument(client, logger=...) monkey-patch
anthropic (AsyncAnthropic) chatbot_sdk.integrations.anthropic.instrument(client, logger=...) monkey-patch
google-genai (AsyncClient) chatbot_sdk.integrations.google.instrument(client, logger=...) monkey-patch
langchain-core chatbot_sdk.integrations.langchain.SDKCallback(sdk=logger) callback handler
llama-index-core chatbot_sdk.integrations.llamaindex.LlamaIndexCallback(logger) callback handler
Anything else async with logger.inference(...) as span: manual context manager

Per-request context

Use logger.context(...) to propagate per-request IDs through nested LLM/tool calls without threading them by hand:

async with logger.context(conversation_id=conv_id, user_id=user_id):
    resp = await client.chat.completions.create(...)   # auto-traced, IDs stamped on the log

Metadata

Release files for inferspect-sdk 0.2.2

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

Source distribution (sdist)

Source distribution for inferspect-sdk 0.2.2
File Size Uploaded Provenance Actions
inferspect_sdk-0.2.2.tar.gz 35.0 kB Without provenance Details for inferspect_sdk-0.2.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for inferspect-sdk 0.2.2
File Interpreter ABI Platform Actions
inferspect_sdk-0.2.2-py3-none-any.whl Python 3 none any Details for inferspect_sdk-0.2.2-py3-none-any.whl

Total release size: 70.0 kB

Release files / inferspect_sdk-0.2.2.tar.gz

Download URL inferspect_sdk-0.2.2.tar.gz
Size 35.0 kB
Tags Source
SHA-256 checksum
How to use checksums
eb9585d8e08192fb418e589d648b0f88e45c76230b864275a7baa0ac7e38b309
BLAKE2b-256 checksum
How to use checksums
c710f6b2192d90c01d5abaa1e393c800813735055d94372ea4958629db1e55b9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.18

Release files / inferspect_sdk-0.2.2-py3-none-any.whl

Download URL inferspect_sdk-0.2.2-py3-none-any.whl
Size 35.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0b40709223a57237ca5e5535300c6eff724dd20013db949449551835c4f2e2f6
BLAKE2b-256 checksum
How to use checksums
59440cee97592bc940ff72e464e7ae8b4fff51b9b854460b0533a50111cd9763
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.18

Security for inferspect-sdk 0.2.2

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