Environment Variables
To set a value to an environment variable, use the following syntax:
Example
Using an environment variable for API key:
Setting Environment Variables
Setting Environment Variables
In the VSCode Playground
Once you open a .baml
file in VSCode, you should see a small button over every BAML function: Open Playground
. Then you should be able to set environment variables in the settings tab.
Or type BAML Playground
in the VSCode Command Bar (CMD + Shift + P
or CTRL + Shift + P
) to open the playground.
For Your App (Default)
BAML will do its best to load environment variables from your program. Any of the following strategies for setting env vars are compatible with BAML:
- Setting them in your shell before running your program
- In your
Dockerfile
- In your
next.config.js
- In your Kubernetes manifest
- From
secrets-store.csi.k8s.io
- From a secrets provider such as Infisical / Doppler
- From a
.env
file (usingdotenv
CLI) - Using account credentials for ephemeral token generation (e.g., Vertex AI Auth Tokens)
python-dotenv
package in Python ordotenv
package in Node.js
python
typescript
ruby
Warning: If you are using the
python-dotenv
package, please check the import order for some edge cases.
For Your App (Manually)
Requires BAML Version 0.57+
Reset the environment variables to those manually set in your code.
python
typescript
ruby
Error Handling
Errors for unset environment variables are only thrown when the variable is accessed. If your BAML project has 15 environment variables and 1 is used for the function you are calling, only that one environment variable will be checked for existence.