File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -132,6 +132,25 @@ for i, response in enumerate(responses):
132132 print (f " Response { i+ 1 } : Request failed. " )
133133```
134134
135+ ### Usage statistics and tracking
136+
137+ ` APIClient ` integrates an ` APIUsageTracker ` that accumulates cost, token usage, and response time stats across all calls.
138+
139+ Quick peek:
140+
141+ ``` python
142+ print (client.tracker) # human-readable summary
143+ print (client.tracker.details) # machine-friendly dict
144+
145+ print (f " Total cost: $ { client.tracker.total_cost:.4f } " )
146+ print (f " Total prompt tokens: { client.tracker.total_prompt_tokens} " )
147+ print (f " Total completion tokens: { client.tracker.total_completion_tokens} " )
148+ print (f " Number of API calls: { client.tracker.num_api_calls} " )
149+ print (f " Mean response time: { client.tracker.mean_response_time:.2f } s " )
150+ ```
151+
152+ See tracker API: https://andrefcruz.github.io/llm-api-client/api.html#module-llm_api_client.api_tracker
153+
135154### Client Parameters
136155
137156The ` APIClient ` constructor accepts:
You can’t perform that action at this time.
0 commit comments