Track AI API costs per client, project, and feature
Project description
Pradvion Python SDK
Track AI API costs per client, project, and feature. Know exactly what to bill each client.
Installation
pip install pradvion
Quick Start
import openai import pradvion
pradvion.init(api_key="nx_live_YOUR_KEY") client = pradvion.wrap(openai.OpenAI())
response = client.chat.completions.create( model="gpt-4o", messages=[{"role": "user", "content": "Hello"}] )
Cost automatically tracked in dashboard
Context Manager
with pradvion.context( feature="resume-summarizer", customer_id="samsung-001", environment="production" ): response = client.chat.completions.create(...)
Middleware Pattern (FastAPI)
@app.middleware("http") async def pradvion_middleware(request, call_next): user = get_current_user(request) pradvion.set_context( customer_id=user.company_id, environment="production" ) response = await call_next(request) pradvion.clear_context() return response
Async Support
async_client = pradvion.wrap(openai.AsyncOpenAI()) response = await async_client.chat.completions.create(...)
Streaming
stream = client.chat.completions.create( model="gpt-4o", messages=[...], stream=True, ) for chunk in stream: print(chunk.choices[0].delta.content, end="")
Usage captured automatically from last chunk
Agent / RAG Usage
with pradvion.context(feature="research-agent", customer_id="samsung"): # All sub-calls tracked under same context search = client.chat.completions.create(...) analyze = client.chat.completions.create(...) report = client.chat.completions.create(...)
Support
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 pradvion-0.1.0.tar.gz.
File metadata
- Download URL: pradvion-0.1.0.tar.gz
- Upload date:
- Size: 8.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7d12dc32c384048e473d48b0bc081cae8905f017642ed957fcd2977b0ed23c71
|
|
| MD5 |
7816aecdc2512e3765f5d101eba5479a
|
|
| BLAKE2b-256 |
5fc82301023bd9d1a2162bb68a2e184ac82414527dd067b5a17facfa1bb390a3
|
File details
Details for the file pradvion-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pradvion-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f4dadfdeca64e6ff0d18c7cd6119d410e3da210134103e7cf257a1ffb7505d10
|
|
| MD5 |
c8f176d06ba29cf2b5b138eae9fe6838
|
|
| BLAKE2b-256 |
2ed4478c816ac1623bf227d248dc5a41d6c54f5b1148a2a7ab1a4b167cdd380d
|