The serve command starts a BAML-over-HTTP API server that exposes your BAML
functions via HTTP endpoints. This feature allows you to interact with your BAML
functions through a RESTful API interface.
If you’re actively developing, you can use the dev command to include
hot-reload functionality:
The serve command performs the following actions:
POST /call/:function_name: Call a BAML function
POST /stream/:function_name: Stream results from a BAML function
Debugging
GET /docs: Interactive API documentation (Swagger UI)GET /openapi.json: OpenAPI specification for the BAML functionsGET /_debug/ping: Health check endpointGET /_debug/status: Server status and authentication checkbaml-cli serve is currently in Tier 2 stability. This means that the CLI and
the HTTP APIs are stable, but there are a number of features which are
not yet available:
We support the header: x-baml-api-key
Set the BAML_PASSWORD environment variable to enable authentication.
Start the server with default settings:
Start the server with a custom source directory and port:
To test the server, you can use the following curl commands:
Check if the server is running:
Call a function:
Access the API documentation:
Open http://localhost:2024/docs in your web browser.