serve
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.
Warning: Preview Feature
- You must include the
--preview
flag when running thedev
command. - Be aware that this feature is still being stabilized and may change in future releases.
Usage
If you’re actively developing, you can use the dev
command to include hotreload functionality:
Options
Description
The serve
command performs the following actions:
- Exposes BAML functions as HTTP endpoints on the specified port.
- Provides authentication middleware for secure access.
Endpoints
POST /call/:function_name
: Call 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 check
Authentication
We support the header: x-baml-api-key
Set the BAML_PASSWORD
environment variable to enable authentication.
Examples
-
Start the server with default settings:
-
Start the server with a custom source directory and port:
Testing
To test the server, you can use the following curl
commands:
-
Check if the server is running:
-
Call a function:
API Key -
Access the API documentation: Open
http://localhost:2024/docs
in your web browser.