The onTick feature allows you to receive real-time callbacks during BAML function execution, providing access to internal state, streaming responses, and progress updates. This is particularly useful for monitoring function progress, debugging, and accessing intermediate data like “thinking” content from streaming LLM responses.
Track the progress of long-running BAML function calls:
Extract intermediate “thinking” content from streaming LLM responses:
Use onTick for comprehensive debugging and logging:
OnTick can be used alongside Collectors for comprehensive logging:
OnTick callbacks should handle errors gracefully. If an onTick callback throws an error, the function execution will continue:
Keep these limitations in mind when using onTick:
Synchronous Functions: OnTick is not supported for synchronous function calls. Attempting to use onTick with sync functions will throw an error.
Error Isolation: Errors in onTick callbacks do not stop function execution, but they may not be explicitly surfaced.
OnTick is passed via the baml_options parameter (Python) or options object (TypeScript/Go):