Set Environment Variables

Environment Variables in BAML

Environment variables are primarily used in clients to propagate authorization credentials, such as API keys, like so:

1client<llm> GPT4o {
2 provider baml-openai-chat
3 options {
4 model gpt-4o
5 api_key env.OPENAI_API_KEY
6 }
7}

Setting Environment Variables in Python/Typescript/etc

The generated BAML client will capture all environment variables when you import it, and will not be able to see any environment variables you load after importing the BAML client.

Any of the following strategies are compatible with BAML:

  • set environment variables in your Dockerfile
  • set environment variables in your next.config.js
  • set environment variables in your Kubernetes manifest
  • load environment variables from secrets-store.csi.k8s.io
  • load environment variables from a secrets provider such as Infisical / Doppler
  • dotenv (.env file) cli (e.g. dotenv -e .env python myscript.py)
  • using account credentials for ephemeral token generation (e.g. Vertex AI Auth Tokens)
If BAML doesn’t work for your use case, please contact us!

Modifying env variables in your program

This is available in Baml Version 0.57+

1from baml_client import b
2from baml_client import reset_baml_env_vars
3import os
4import dotenv
5
6dotenv.load_dotenv()
7reset_baml_env_vars(dict(os.environ))

We do not currently support any other mechanisms for providing authorization credentials, including but not limited to:

  • fetching credentials from a secret storage service, such as AWS Secrets Manager or HashiCorp Vault

Please contact us if you need support for these use cases.