View source on GitHub
Features
- Auto-detects conversation version (V0 vs V1) and uses the appropriate API
- Graceful fallback chain for metric retrieval
- Displays cost (USD), token counts, cache stats, and context window
- JSON output for programmatic use
- API call logging for debugging and development
- Fixture-based testing - high coverage via recorded API responses
- Zero dependencies - uses only Python standard library
How It Works
The tool uses a fallback chain to find metrics:- Check conversation version via
/api/conversations/{id} - For V1 conversations:
- First try
/api/v1/app-conversations?ids={id}which includes ametricsobject - If metrics are all zeros, fall back to
/api/v1/conversation/{id}/events/searchand extract metrics fromConversationStateUpdateEventatvalue.stats.usage_to_metrics.agent
- First try
- For V0 conversations (or if V1 fails): Use
/api/conversations/{id}/eventsand find the latest event withllm_metrics - Last resort: Use
/api/conversations/{id}/trajectoryand scan forllm_metrics
Note: Some V1 conversations have metrics stored only in events (not in the app-conversations response). The fallback chain ensures these are still retrieved correctly.
Installation
No installation required - just make the script executable:Run It
Set your API key
Get metrics for a conversation
JSON output
Options
Logging API Calls
For debugging or development, you can log all API requests and responses:.oh/api-logs/YYYYMMDD-HHMMSS/:
Metrics Explained
Architecture
The library is organized into separate modules:Using the Library Programmatically
Using the V0/V1 Drivers Directly
Testing
The test suite uses recorded API fixtures to achieve high coverage without making real API calls:Creating New Fixtures
- Run the CLI with
--log-api-callsto capture real API responses - Copy relevant response files to
tests/fixtures/ - Rename following the pattern:
GET__api_path_q_param=value.json

