OnTick
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.
Quick Start
Python
TypeScript
Go
Common Use Cases
Progress Monitoring
Track the progress of long-running BAML function calls:
Python
TypeScript
Go
Accessing Streaming “Thinking” Content
Extract intermediate “thinking” content from streaming LLM responses:
Python
TypeScript
Go
Debugging and Logging
Use onTick for comprehensive debugging and logging:
Python
TypeScript
Go
Using with Collectors
OnTick can be used alongside Collectors for comprehensive logging:
Python
TypeScript
Go
Error Handling
OnTick callbacks should handle errors gracefully. If an onTick callback throws an error, the function execution will continue:
Python
TypeScript
Go
Limitations
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.
API Reference
OnTick Callback Signature
Python
TypeScript
Go
Integration with Function Calls
OnTick is passed via the baml_options
parameter (Python) or options object (TypeScript/Go):
Python
TypeScript
Go
Related Topics
- Collector - Learn about comprehensive logging with Collectors
- Using with_options - Configure global options for BAML functions
- Streaming - Understand streaming function calls
Best Practices
- Keep Callbacks Light: OnTick callbacks should be fast and non-blocking
- Handle Errors Gracefully: Always include error handling in your callbacks
- Use with Collectors: Combine onTick with Collectors for comprehensive logging
- Monitor Performance: Test the performance impact for your specific use case
- Async Only: Remember that onTick only works with async function calls, not sync calls