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.
You can use multiple collectors to track different aspects of your application:
When using providers that support prompt caching (like Anthropic, OpenAI, Google, or Vertex), you can track cached input tokens via the cached_input_tokens field:
Cached token tracking is supported for Anthropic, OpenAI, Google AI, and Vertex AI providers. AWS Bedrock does not currently support cached token reporting and will return null for this field.
The Collector class provides properties to introspect the internal state of BAML function calls.
The Collector class provides the following methods:
The FunctionLog class has the following properties:
The Timing class has the following properties:
The Usage class has the following properties:
Note: Usage may not include all provider-specific token types like “thinking_tokens” or “cache_creation_input_tokens”. For those, you may need to look at the raw HTTP response and build your own adapters.
The LLMCall class has the following properties:
The LLMStreamCall includes the same properties as LLMCall plus the following:
The HttpRequest class has the following properties:
The HttpResponse class has the following properties:
The HTTPBody class has the following properties:
http_response will be null, but you can still access usage information.