Docker
When you develop with BAML, the BAML VScode extension generates a baml_client directory (on every save) with all the generated code you need to use your AI functions in your application.
We recommend you add baml_client to your .gitignore file to avoid committing generated code to your repository, and re-generate the client code when you build and deploy your application.
You could commit the generated code if you’re starting out to not deal with this, just make sure the VSCode extension version matches your baml package dependency version (e.g. baml-py for python and @boundaryml/baml for TS) so there are no compatibility issues.
To build your client you can use the following command. See also baml-cli generate:
Go: Multi-stage Docker builds
When using Go, the baml-cli generate command downloads the libbaml-cffi native library that BAML needs at runtime. This library is cached to avoid downloading it every time your container runs.
Single-stage builds
For single-stage builds, running baml-cli generate (as shown above) will automatically download and cache libbaml-cffi in your Docker image.
Multi-stage builds
For multi-stage Docker builds, you need to ensure libbaml-cffi is available in your final image. You have two options:
Option 1: Copy the cache directory
Set the BAML_CACHE_DIR environment variable in both stages and copy it to your final image:
Option 2: Regenerate in the final stage
Install baml-cli in your final image and run baml-cli --version (or baml-cli generate) to download libbaml-cffi:
Customizing the cache directory
By default, BAML downloads libbaml-cffi to a system-specific cache directory. You can control this location using the BAML_CACHE_DIR environment variable:
This is particularly useful when you want to explicitly control where the native library is stored in your container.