Installation Steps
Install BAML VSCode/Cursor Extension
Install the extension from: https://marketplace.visualstudio.com/items?itemName=boundary.baml-extensionFeatures include:
- Syntax highlighting
- Testing playground
- Prompt previews
Install BAML CLI and Initialize Project
Install the BAML CLI tool globally and create starter BAML code:This will:
- Install the BAML CLI tool globally
- Create starter BAML code in a
baml_srcdirectory - Set up the basic project structure
Generate the baml_client Module
One of the files in your Any types defined in
baml_src directory will have a generator block. Run this command to auto-generate the baml_client module with Rust code:.baml files will be converted into Rust structs and enums.Build Integration
You can modify your build process to always callbaml-cli generate before building:
Makefile
Working with Cargo
BAML integrates seamlessly with Cargo. Ensure yourCargo.toml includes the BAML dependency:
Cargo.toml
baml_client module lives inside your crate:
Error Handling
All BAML Rust function calls returnResult<T, baml_client::Error>:
Cancellation and Timeouts
Rust usesCancellationToken for cancellation and timeouts: