Skip to main content

Installation Steps

1

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
2

Install BAML

Install the @boundaryml/baml package using your preferred package manager:
npm install @boundaryml/baml
3

Initialize BAML in Your Project

This creates a baml_src directory with starter BAML code:
npx baml-cli init
4

Generate the baml_client Package

One of the files in your baml_src directory will have a generator block. Run this command to auto-generate the baml_client directory with TypeScript code to call your BAML functions:
npx baml-cli generate
For ESM compatibility, add this to your .baml generator configuration:
generator typescript {
  ...
  module_format "esm"  // default is "cjs" for CommonJS
}
If you have the VSCode extension installed, it will automatically run baml-cli generate when you save a BAML file.
5

Use BAML Functions in TypeScript

Import and use your generated BAML client:
import { b } from "./baml_client"
import type { Resume } from "./baml_client/types"

async function Example(raw_resume: string): Promise<Resume> {
  // BAML's internal parser guarantees ExtractResume
  // to always return a Resume type
  const response = await b.ExtractResume(raw_resume);
  return response;
}

async function ExampleStream(raw_resume: string): Promise<Resume> {
  const stream = b.stream.ExtractResume(raw_resume);
  for await (const msg of stream) {
    console.log(msg)  // Partial<Resume> type
  }

  // Guaranteed to be a Resume type
  return await stream.getFinalResponse();
}

Build Integration

You can modify your package.json to run baml-cli generate before building:
package.json
{
  "scripts": {
    "baml-generate": "baml-cli generate",
    "build": "npm run baml-generate && tsc --build"
  }
}
This ensures your generated client is always up-to-date when you build your project.

Build docs developers (and LLMs) love