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
Ruby
Common Use Cases
Basic Logging
Python
TypeScript
Ruby
Managing Collector State
Python
TypeScript
Ruby
Using Multiple Collectors
You can use multiple collectors to track different aspects of your application:
Python
TypeScript
Ruby
Usage Tracking
Python
TypeScript
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:
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.
- Clear the collector when reusing it for unrelated operations.
- 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_response
will be null, but you can still access usage information.