Collector
This feature was added in 0.79.0
The Collector allows you to inspect the internal state of BAML function calls, including raw HTTP requests, responses, usage metrics, and timing information, so you can always see the raw data, without any abstraction layers.
Quick Start
Python
TypeScript
Go
Ruby
Common Use Cases
Basic Logging
Python
TypeScript
Go
Ruby
Managing Collector State
Python
TypeScript
Go
Ruby
Using Multiple Collectors
You can use multiple collectors to track different aspects of your application:
Python
TypeScript
Go
Ruby
Usage Tracking
Python
TypeScript
Go
Ruby
API Reference
Collector Class
The Collector class provides properties to introspect the internal state of BAML function calls.
The Collector class provides the following methods:
FunctionLog Class
The FunctionLog class has the following properties:
Timing Class
The Timing class has the following properties:
StreamTiming Class (extends Timing)
Usage Class
The Usage class has the following properties:
Note: Usage may not include all things like “thinking_tokens” or “cached_tokens”. For that you may need to look at the raw HTTP response and build your own adapters.
LLMCall Class
The LLMCall class has the following properties:
LLMStreamCall Class (extends LLMCall)
The LLMStreamCall includes the same properties as LLMCall plus the following:
HttpRequest Class
The HttpRequest class has the following properties:
HttpResponse Class
The HttpResponse class has the following properties:
HTTPBody Class
The HTTPBody class has the following properties:
Related Topics
- Using with_options - Learn how to configure logging globally
- TypeBuilder - Build custom types for your BAML functions
- Client Registry - Manage LLM clients and their configurations
Best Practices
- Use a single collector instance when tracking related function calls in a chain.
- Consider using multiple collectors to track different parts of your application.
- Use function IDs when tracking specific calls in parallel operations.
- For streaming calls, be aware that
http_responsewill be null, but you can still access usage information.