baml init command creates a new BAML project with the necessary directory structure and configuration files to get you started.
Usage
Options
Directory where the BAML project will be initialized. Defaults to the current directory.
Type of BAML client to generate. If not specified, the command attempts to detect the project type automatically based on files in the destination directory.Available options:
python/pydantic- Python clients using Pydantic modelstypescript- TypeScript clientsgo- Native Go clientsruby/sorbet- Ruby clients with Sorbet type annotationsrest/openapi- REST API via OpenAPI specificationrust- Native Rust clients
OpenAPI client generator to use when
--client-type=rest/openapi.Examples: go, java, php, ruby, rust, csharpSee the full list in the OpenAPI Generator documentation.What It Does
When you runbaml init, the command:
-
Detects your project type - Automatically identifies whether you’re using Python, TypeScript, Go, Ruby, or another language by checking for project files like
package.json,pyproject.toml,go.mod, orGemfile -
Creates project structure - Sets up a
baml_src/directory containing:generators.baml- Configuration for code generationclients.baml- Sample LLM client configurationsresume.baml- Example function to get you started
- Configures generators - Creates generator configuration matching your detected or specified project type, with appropriate settings for output directory, version, and client mode
- Sets up editor extensions - Automatically detects VSCode or Cursor and attempts to install the BAML extension for syntax highlighting and language support
-
Copies editor rules - For Cursor users, sets up
.cursor/rules/baml.mdcwith helpful AI prompts for working with BAML
Project Type Detection
The command automatically detects your project type by looking for:- Python:
uv.lock,pyproject.toml,requirements.txt, orsetup.py - TypeScript:
package.json - Go:
go.mod - Ruby:
Gemfile
Examples
Basic initialization
Initialize in the current directory with auto-detected project type:Initialize in a specific directory
Initialize for Python
Initialize for TypeScript
Initialize for Go
Initialize with OpenAPI for Java
Output
Successful initialization creates the following structure:Troubleshooting
Project already exists
Error: “Looks like you already have a BAML project at ./baml_src” Solution: The destination directory already contains abaml_src folder. Either:
- Choose a different destination with
--dest - Remove or rename the existing
baml_srcdirectory - Use the existing project instead of initializing a new one
OpenAPI generator not found
Warning: “Failed to find openapi-generator-cli in your PATH” Solution: When using--client-type=rest/openapi, install the OpenAPI generator:
npx @openapitools/openapi-generator-cli if available.
Extension installation fails
Issue: BAML extension doesn’t install automatically Solution: Manually install the extension:- Open VSCode or Cursor
- Go to Extensions (Cmd/Ctrl+Shift+X)
- Search for “BAML”
- Click Install
Go package name detection
Warning: “Failed to find go.mod file, please update the client_package_name” Solution: If initializing a Go project without an existinggo.mod, manually update the client_package_name in baml_src/generators.baml after running go mod init:
Next Steps
After initialization:-
Set up API keys - Create a
.envfile with your LLM provider credentials: -
Generate client code - Run code generation:
-
Explore the example - Check out
baml_src/resume.bamlto see how BAML functions work - Start building - Create your own BAML functions or modify the example
- Read the docs - Visit https://docs.boundaryml.com for comprehensive guides
Related Commands
baml generate- Generate client code from BAML filesbaml dev- Start development server with hot reloadbaml test- Run tests for your BAML functions