Skip to main content

prism-sdk

LLM Observability in 3 lines. Costs, latency, errors and quality — automatically.

pip install useprism

Quick Start

With Anthropic

import anthropic
import prism

# 1. Init
prism.init("prism_your_api_key")

# 2. Wrap your client
client = prism.wrap(anthropic.Anthropic())

# 3. Use exactly as before — everything is traced automatically
response = client.messages.create(
    model="claude-sonnet-4-6",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Summarise this contract..."}],
)

With OpenAI

import openai
import prism

prism.init("prism_your_api_key")
client = prism.wrap(openai.OpenAI())

response = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Hello!"}],
)

With a custom / unsupported client

import prism
from prism.manual import trace

prism.init("prism_your_api_key")

with trace("my-model", endpoint="/api/summarize") as t:
    result = my_custom_llm_call(prompt)
    t.set_tokens(prompt=500, completion=200)
    t.set_response(result.text)

Configuration

prism.init(
    api_key="prism_your_api_key",
    debug=True,           # print logs to stdout
    flush_interval=2.0,   # seconds between batch flushes
    batch_size=20,        # traces per batch request
)

What gets tracked automatically

Field Description
model Model name (e.g. claude-sonnet-4-6)
provider anthropic / openai / google
prompt_tokens Input tokens used
completion_tokens Output tokens used
cost_usd Calculated cost (server-side)
latency_ms End-to-end response time
status_code 200 on success, 4xx/5xx on errors
prompt_preview First 500 chars of the prompt
response_preview First 500 chars of the response

FastAPI integration example

from fastapi import FastAPI, Request
import anthropic
import prism

prism.init("prism_your_api_key")
app = FastAPI()

@app.post("/api/chat")
async def chat(request: Request):
    body = await request.json()

    # Wrap per-request for endpoint-level tracking
    client = prism.wrap(
        anthropic.Anthropic(),
        endpoint="/api/chat",
    )

    response = client.messages.create(
        model="claude-sonnet-4-6",
        max_tokens=1024,
        messages=[{"role": "user", "content": body["message"]}],
    )
    return {"reply": response.content[0].text}

Overhead

  • ~0ms added to your LLM calls (async background thread)
  • Traces are batched and sent every 2 seconds
  • On shutdown, all pending traces are flushed

License

MIT

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

useprism-0.4.0.tar.gz (10.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

useprism-0.4.0-py3-none-any.whl (11.2 kB view details)

Uploaded Python 3

File details

Details for the file useprism-0.4.0.tar.gz.

File metadata

  • Download URL: useprism-0.4.0.tar.gz
  • Upload date:
  • Size: 10.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.5

File hashes

Hashes for useprism-0.4.0.tar.gz
Algorithm Hash digest
SHA256 b02e956b322c8e81cb58253e96fefc52156de064626b7104953edd910218305f
MD5 d9d57afc1ca1dded9da3924616dbe7eb
BLAKE2b-256 364ee5f6a5b7c0120eeb7e0434e46d8f6c83c8c0f130f85bc94f2734e80d7493

See more details on using hashes here.

File details

Details for the file useprism-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: useprism-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 11.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.5

File hashes

Hashes for useprism-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f4cc5289e3fc10bcaf5dd1d19f4f9d12a77b0d02fd1bdc29c31694e5f6486fac
MD5 a0a16d6de90161ffac2b6ffd41879a4f
BLAKE2b-256 ba05d7b5c85a16305020ec35020eb282f645346748bbc0bf7e5d70b92457a8e8

See more details on using hashes here.

Release history Release notifications | RSS feed

0.7.0

2 files

0.6.0

2 files

0.5.0

2 files

This release

0.4.0 This release

2 files

0.3.0

2 files

0.2.0

2 files

0.1.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page