Core Concepts
How TokenSense intercepts calls
TokenSense wraps your LLM client using Python’s__getattr__ proxy pattern. When you call client.messages.create(...), TokenSense:
- Forwards the call to the original client — unchanged
- Waits for the response
- Extracts metadata from the response (tokens, model, cost)
- Emits a
CallEventto a background thread - Returns the original response to your code
