Back to Baml

Get Started

fern/01-guide/functions/get-started.mdx

0.222.03.5 KB
Original Source

Learn how to host your BAML code on Boundary Functions and call it over HTTP.

<Info> This is a preview feature, available starting with `baml-cli v0.66.0`. </Info> <Note> The BAML language, compiler, and runtime will always be 100% free and open-source: we will always allow you to run BAML functions directly in your own backends.

Boundary Functions' goal is to make it even easier to host and run BAML functions, by adding support for features like rate limits, telemetry, and end-user feedback. </Note>

Boundary Functions allows you to host your BAML functions on our infrastructure, exposing one REST API endpoint per BAML function.

<div class="flex flex-col items-center"> </div>

This guide will walk you through:

  • creating a Boundary Cloud account,
  • deploying your BAML code to Boundary Functions,
  • setting your API keys, and
  • calling your BAML functions.

Once you've deployed your BAML functions, you can use the OpenAPI client to call them.

Get Started

First, create your account and organization at https://dashboard.boundaryml.com.

Then, log in from your terminal:

bash
baml-cli login

and run this command in your baml_src/ directory:

bash
baml-cli deploy

This will prompt you to create a new Boundary project, deploy your BAML code to it, and then point you to the dashboard, where you can set environment variables and create API keys to use to call your BAML functions.

<div class="flex flex-col items-center"> </div>

Once you've set the environment variables you need (probably ANTHROPIC_API_KEY and/or OPENAI_API_KEY), you can call your BAML functions!

If you still have the ExtractResume function that your BAML project was created with, you can use this command to test it out:

bash
curl https://api2.boundaryml.com/v3/functions/prod/call/ExtractResume \
  -H "Authorization: Bearer $BOUNDARY_API_KEY" \
  -H "Content-Type: application/json" \
  -d @- << EOF
{
  "resume": "
    Grace Hopper
    [email protected]

    Experience:
    - Rear Admiral, US Navy
    - Senior Programmer, Eckert-Mauchly Computer Corporation
    - Associate Professor, Vassar College

    Skills:
    - COBOL
    - Compiler development
  "
}
EOF

Congratulations! You've gotten your first BAML functions working on Boundary Functions.

Local development and testing

To test your BAML functions locally, you can use baml-cli dev:

bash
ANTHROPIC_API_KEY=... OPENAI_API_KEY=... baml-cli dev

which will allow you to call your functions at http://localhost:2024/call/<function_name> instead of https://api2.boundaryml.com/v3/functions/prod/call/<function_name> using the exact same curl command:

bash
curl http://localhost:2024/functions/prod/call/ExtractResume \
  -H "Authorization: Bearer $BOUNDARY_API_KEY" \
  -H "Content-Type: application/json" \
  -d @- << EOF
{
  "resume": "
    Grace Hopper
    [email protected]

    Experience:
    - Rear Admiral, US Navy
    - Senior Programmer, Eckert-Mauchly Computer Corporation
    - Associate Professor, Vassar College

    Skills:
    - COBOL
    - Compiler development
  "
}
EOF
<div class="flex flex-col items-center"> </div>