How to automatically track OpenAI and Anthropic API costs, latency, and token usage in Python?
03:47 11 May 2026

I'm building a Python application that makes frequent calls to

OpenAI and Anthropic APIs. I want to monitor:

- How much each call costs in USD

- Latency per call (ms)

- Token usage (input/output)

- Error rate

I don't want to manually wrap every API call or sign up for

an external service. Is there a lightweight way to add this

observability without changing my existing code?

Python 3.11, using openai and anthropic official SDKs.

python openai-api large-language-model apimonitor anthropic