> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.boundaryml.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.boundaryml.com/_mcp/server.

# config (logging / environment variables)

Various settings are configurable via environment variables.

| Setting            | Environment Variable          | Description                                                                 | Default |
| ------------------ | ----------------------------- | --------------------------------------------------------------------------- | ------- |
| Logging Level      | `BAML_LOG`                    | The logging level to use (`INFO`, `DEBUG`, `TRACE`, `WARN`, `ERROR`, `OFF`) | `INFO`  |
| Text / JSON Mode   | `BAML_LOG_JSON`               | Whether to log in JSON format or human-readable format (`1`, `0`)           | `0`     |
| Max Log Chunk Size | `BAML_LOG_MAX_MESSAGE_LENGTH` | How large of a prompt / response will be logged (`0` for no limit)          | `64000` |
| Log Color Mode     | `BAML_LOG_COLOR_MODE`         | Whether to color the log output (`auto`, `always`, `never`)                 | `auto`  |

Setting can also be modified via functions in `baml_client.config`.

```python
from baml_client.config import set_from_env, set_log_level, 
                               set_log_json_mode, set_log_max_message_length,
                               get_log_level, reset_baml_env_vars
```

### set\_log\_level

Environment variable: `BAML_LOG`

```python
def set_log_level(level: "INFO" | "DEBUG" | "TRACE" | "WARN" | "ERROR" | "OFF"):
  ...
```

### set\_log\_json\_mode

Environment variable: `BAML_LOG_JSON`

Switches the log output between JSON and human-readable format.

```python
def set_log_json_mode(enable: bool):
```

### set\_log\_max\_message\_length

`0` for unlimited

Environment variable: `BAML_LOG_MAX_MESSAGE_LENGTH`

```python
def set_log_max_message_length(length: int):
```

### get\_log\_level

```python
def get_log_level() -> "INFO" | "DEBUG" | "TRACE" | "WARN" | "ERROR" | "OFF":
```

### reset\_baml\_env\_vars

`reset_baml_env_vars` is deprecated and is safe to remove, since environment variables are now lazily loaded on each function call

Resets the environment variables to the values in the provided dictionary.
Will also reset any logging related environment variables to those passed in (if set explicitly).

```python
def reset_baml_env_vars(env: Dict[str, str]):
```

```typescript
import { setLogLevel, setLogJsonMode, 
         setLogMaxMessageLength, getLogLevel,
         resetBamlEnvVars } from '@/baml_client/config';
```

### setLogLevel

Environment variable: `BAML_LOG`

```typescript
setLogLevel(level: "INFO" | "DEBUG" | "TRACE" | "WARN" | "ERROR" | "OFF"): void;
```

### setLogJsonMode

Environment variable: `BAML_LOG_JSON`

Switches the log output between JSON and human-readable format.

```typescript
setLogJsonMode(enable: boolean): void;
```

### setLogMaxMessageLength

Environment variable: `BAML_LOG_MAX_MESSAGE_LENGTH`

`0` for unlimited

```typescript
setLogMaxMessageLength(length: number): void;
```

### getLogLevel

```typescript
getLogLevel(): "INFO" | "DEBUG" | "TRACE" | "WARN" | "ERROR" | "OFF";
```

### resetBamlEnvVars

Resets the environment variables to the values in the provided dictionary.
Will also reset any logging related environment variables to those passed in (if set explicitly).

```typescript
resetBamlEnvVars(env: Record<string, string | undefined>): void;
```

```rust
// Rust uses environment variables directly.
// Set BAML_LOG, BAML_LOG_JSON, etc. before running your application,
// or use .with_env_var() on function calls to override per-call.
use myproject::baml_client::sync_client::B;

let result = B.ExtractResume
    .with_env_var("BAML_LOG", "DEBUG")
    .call("...")
    .unwrap();
```

```ruby
# not implemented yet
# please use environment variables instead
```

<hr />

## 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.

<img src="https://files.buildwithfern.com/https://boundary.docs.buildwithfern.com/2026-06-19T22:23:03.688Z/assets/vscode/code-lens.png" alt="VSCode Code Lens" />

Or type `BAML Playground` in the VSCode Command Bar (`CMD + Shift + P` or `CTRL + Shift + P`) to open the playground.

### For Boundary Studio Integration

To send logs and traces to Boundary Studio, you need to set the `BOUNDARY_API_KEY` environment variable. This key is provided when you create an API key in your Boundary Studio dashboard.

```bash
# .env.local
BOUNDARY_API_KEY=your_api_key_here
```

```bash
# .env
BOUNDARY_API_KEY=your_api_key_here
```

```bash
# .env
BOUNDARY_API_KEY=your_api_key_here
```

```yaml
# config/application.yml
BOUNDARY_API_KEY: your_api_key_here
```

### 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](https://infisical.com/) / [Doppler](https://www.doppler.com/)
* From a `.env` file (using `dotenv` CLI)
* Using account credentials for ephemeral token generation (e.g., Vertex AI Auth Tokens)
* `python-dotenv` package in Python or `dotenv` package in Node.js

```bash
export MY_SUPER_SECRET_API_KEY="..."
python my_program_using_baml.py
```

```python
from dotenv import load_dotenv
from baml_client import b

load_dotenv()
```

```typescript
import dotenv from 'dotenv'
import { b } from './baml_client'

dotenv.config()
```

```ruby
require 'dotenv/load'
require 'baml_client'
```