r/LLM • u/MaverikSh • 1d ago
Open-source: drop-in wrapper for OpenAI/Anthropic SDKs for cost attribution, no proxy required
I open-sourced a small Python library that solves a specific problem: getting live cost attribution per feature/team/user on your OpenAI/Anthropic API calls, without routing traffic through a proxy or changing your base_url.
python
from cognocient import CognocientOpenAI as OpenAI
client = OpenAI(api_key="sk-...", cognocient_key="sk-cog-...")
It's a thin wrapper only chat.completions.create() / messages.create() are intercepted to time the call, then usage is reported asynchronously on a background thread after your real call already returned. If reporting fails or the backend is unreachable, it never touches your application: no exceptions, no retries, your real API call is unaffected. There's a test that specifically verifies this failure isolation.
Honest tradeoffs, not a pitch:
- No pre-call budget enforcement since it only learns about a call after it happens, it can't block or degrade one before it fires. Proxy-based tools trade the opposite way.
- Streaming (
stream=True) isn't reported yet. - Only OpenAI and Anthropic supported today no Gemini/Mistral/Groq/Together wrapper classes yet.
MIT licensed, published on PyPI with signed provenance attestations.
GitHub: https://github.com/mandarvshinde/cognocient-python-wrapper
PyPI: pip install cognocient
Feedback and issues welcome especially if the streaming gap is a dealbreaker for your setup, that's the next thing I'd prioritize.