For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
Help on Discord
HomeGuideExamplesBAML ReferencePlaygroundAgents.mdChangelog
HomeGuideExamplesBAML ReferencePlaygroundAgents.mdChangelog
  • Introduction
    • What is BAML?
    • Why BAML?
    • What's the baml_src folder
    • What's baml_client
  • Installation: Editors
    • VSCode Extension
    • Cursor Extension
    • JetBrains IDEs
    • Zed
    • Claude Code
    • Others
  • Installation: Language
    • Python
    • Typescript
    • Go
    • Ruby
    • Rust
    • REST API (other languages)
    • Elixir
  • Framework Integration
  • Development
    • Environment Variables
    • Terminal Logs
    • Upgrade BAML versions
  • BAML Basics
    • Prompting with BAML
    • Switching LLMs
    • Testing functions
    • Streaming
    • Multi-Modal (Images / Audio)
    • Error Handling
    • Configuring Timeouts
    • Concurrent Calls
    • AbortSignal / Cancellation
  • BAML Advanced
    • Collector (track tokens)
    • LLM Client Registry
    • Dynamic Types
    • Reusing Prompt Snippets
    • Prompt Caching / Message Role Metadata
    • Checks and Asserts
    • Modular API
    • Prompt Optimization
  • Boundary Cloud
  • Comparisons
    • BAML vs Langchain
    • BAML vs Marvin
    • BAML vs Ai-SDK
    • BAML vs OpenAI SDK
    • BAML vs Pydantic
    • Contact
Help on Discord
LogoLogo
Installation: Language

REST API (other languages)

Was this page helpful?
Edit this page
Previous

Elixir

Next
Built with

Requires BAML version >=0.55

This feature is a preview feature and may change. Please provide feedback either in Discord or on GitHub so that we can stabilize the feature and keep you updated!

BAML allows you to expose your BAML functions as RESTful APIs:

We integrate with OpenAPI (universal API definitions), so you can get typesafe client libraries for free!

1

Install BAML VSCode Extension

https://marketplace.visualstudio.com/items?itemName=boundary.baml-extension

  • syntax highlighting
  • testing playground
  • prompt previews
2

Install NPX + OpenAPI

macOS (brew)
Linux (apt)
Linux (yum/dnf)
Windows
Other
$brew install npm openapi-generator
$# 'npm' will install npx
$# 'openapi-generator' will install both Java and openapi-generator-cli
3

Add BAML to your existing project

This will give you some starter BAML code in a baml_src directory.

C#
C++
Go
Java
PHP
Ruby
Rust
Other
$npx @boundaryml/baml init \
> --client-type rest/openapi --openapi-client-type csharp
4

Start the BAML development server

$npx @boundaryml/baml dev --preview

This will do four things:

  • serve your BAML functions over a RESTful interface on localhost:2024
  • generate an OpenAPI schema in baml_client/openapi.yaml
  • run openapi-generator -g $OPENAPI_CLIENT_TYPE in baml_client directory to generate an OpenAPI client for you to use
  • re-run the above steps whenever you modify any .baml files

BAML-over-REST is currently a preview feature. Please provide feedback either in Discord or on GitHub so that we can stabilize the feature and keep you updated!

5

Check that the server is running

After running the npx @boundaryml/baml dev command, you can check that the server is up and running by making an HTTP request to these routes:

  1. http://localhost:2024/_debug/ping: Open in the browser or use curl to check that the server is up. You should see a text response similar to this: pong (from baml v0.206.1).

  2. http://localhost:2024/docs: Open in the browser to see and interact with all your routes through the Swagger UI generated from the OpenAPI schema.

If using Docker, replace localhost with the container hostname or IP as appropriate.

6

Use a BAML function in any language!

openapi-generator will generate a README with instructions for installing and using your client; we’ve included snippets for some of the most popular languages below. Check out baml-examples for example projects with instructions for running them.

We’ve tested the below listed OpenAPI clients, but not all of them. If you run into issues with any of the OpenAPI clients, please let us know, either in Discord or by commenting on GitHub so that we can either help you out or fix it!

Go
Java
PHP
Ruby
Rust

Run this with go run main.go:

main.go
1package main
2
3import (
4 "context"
5 "fmt"
6 "log"
7 baml "my-golang-app/baml_client"
8)
9
10func main() {
11 cfg := baml.NewConfiguration()
12 b := baml.NewAPIClient(cfg).DefaultAPI
13 extractResumeRequest := baml.ExtractResumeRequest{
14 Resume: "Ada Lovelace (@gmail.com) was an English mathematician and writer",
15 }
16 resp, r, err := b.ExtractResume(context.Background()).ExtractResumeRequest(extractResumeRequest).Execute()
17 if err != nil {
18 fmt.Printf("Error when calling b.ExtractResume: %v\n", err)
19 fmt.Printf("Full HTTP response: %v\n", r)
20 return
21 }
22 log.Printf("Response from server: %v\n", resp)
23}