Any Language (OpenAPI)
This feature was added in: v0.55.0.
BAML allows you to expose your BAML functions as RESTful APIs:
We also make it easy to generate an OpenAPI client based on your BAML functions, so that you can get a client library for free.
Install the BAML developer tools
-
Install the VSCode extension (marketplace) for syntax highlighting, real-time prompt previews, and an interactive testing playground.
-
Install
npx
andjava
, which you’ll need to run BAML andopenapi-generator
respectivelymacOS (brew)
Linux (apt)
Linux (yum/dnf)
Windows
Other
If you can’t use
npx
, please let us know!It’s currently the easiest way to use BAML and
openapi-generator
, but depending on your needs, we can also provide a static binary for using BAML.
Create a new BAML project
This will give you some starter BAML code in a baml_src
directory, and also
set up generator.baml
based on --openapi-client-type
, so that BAML will:
- compile your BAML functions into an OpenAPI specification, and
- configure
on_generate
to generate an OpenAPI client in the language of your choosing
C#
C++
Go
Java
PHP
Ruby
Rust
Other
Start the development server
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
inbaml_client
to generate an OpenAPI client for you to use - re-run the above steps whenever you modify your
.baml
files
Use your OpenAPI client
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.
Go
Java
PHP
Ruby
Rust
Run this with go run main.go
:
Read on to learn how to deploy your BAML functions.