Skip to content

Commit fa9fbe2

Browse files
Add usage tracking documentation to README with example code
Co-authored-by: andrecruz97 <andrecruz97@gmail.com>
1 parent 578e10c commit fa9fbe2

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff 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

137156
The `APIClient` constructor accepts:

0 commit comments

Comments
 (0)