Skip to main content
BAML-over-REST requires BAML version >=0.55
This feature is in preview and may change. Please provide feedback in Discord or on GitHub.
BAML allows you to expose your BAML functions as RESTful APIs. We integrate with OpenAPI, so you can get type-safe client libraries for free in any language.

Supported Languages

Through OpenAPI, BAML supports:
  • C#
  • C++ (5 different client types)
  • Elixir
  • Go
  • Java
  • PHP
  • Ruby
  • Rust
  • And many more

Installation Steps

1

Install BAML VSCode Extension

Install the extension from: https://marketplace.visualstudio.com/items?itemName=boundary.baml-extensionFeatures include:
  • Syntax highlighting
  • Testing playground
  • Prompt previews
2

Install NPX and OpenAPI

brew install npm openapi-generator
# 'npm' will install npx
# 'openapi-generator' will install both Java and openapi-generator-cli
3

Initialize BAML with OpenAPI

Choose your target language and run the corresponding init command:
npx @boundaryml/baml init \
  --client-type rest/openapi --openapi-client-type csharp
This creates a baml_src directory with starter BAML code.
4

Start the BAML Development Server

npx @boundaryml/baml dev --preview
This will:
  • Serve your BAML functions over REST on localhost:2024
  • Generate an OpenAPI schema in baml_client/openapi.yaml
  • Generate an OpenAPI client in the baml_client directory
  • Re-run these steps whenever you modify .baml files
5

Verify the Server is Running

Check that the server is running:
  1. Ping endpoint: Visit http://localhost:2024/_debug/ping or use curl. You should see:
    pong (from baml v0.206.1)
    
  2. Swagger UI: Visit http://localhost:2024/docs to see and interact with all your routes.
If using Docker, replace localhost with the container hostname or IP.
6

Use BAML Functions in Your Language

The openapi-generator will create a README in the baml_client directory with instructions for your specific language.
Check out baml-examples for working examples in various languages.

Example Usage

package main

import (
  "context"
  "fmt"
  "log"
  baml "my-golang-app/baml_client"
)

func main() {
  cfg := baml.NewConfiguration()
  b := baml.NewAPIClient(cfg).DefaultAPI
  extractResumeRequest := baml.ExtractResumeRequest{
    Resume: "Ada Lovelace (@gmail.com) was an English mathematician",
  }
  resp, r, err := b.ExtractResume(context.Background()).ExtractResumeRequest(extractResumeRequest).Execute()
  if err != nil {
    fmt.Printf("Error: %v\n", err)
    return
  }
  log.Printf("Response: %v\n", resp)
}

Known Limitations

The PHP OpenAPI generator doesn’t support OpenAPI’s oneOf type, which BAML uses for union types. Let us know if this affects you.

Next Steps

For language-specific examples and deployment guides, check out:

Build docs developers (and LLMs) love