Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Promptfoo Promptfoo Environment Variables

From Leeroopedia
Knowledge Sources
Domains Configuration, Runtime
Last Updated 2026-02-14 07:45 GMT

Overview

Concrete tool for providing typed, centralized access to all environment variables used by promptfoo, including feature flags, API keys, and runtime configuration.

Description

The Environment_Variables module (envars.ts) acts as the single point of access for all environment variable reads across the codebase. It loads .env files via dotenv, defines a comprehensive typed EnvVars interface covering 100+ environment variables, and provides type-safe getter functions (getEnvString, getEnvBool, getEnvInt, getEnvFloat) that handle parsing, default values, and provider-specific overrides via the EnvOverrides object.

Usage

Import the getter functions whenever code needs to read an environment variable. This ensures consistent parsing and allows the EnvOverrides system to override values on a per-provider basis.

Code Reference

Source Location

Signature

export function getEnvString(
  key: keyof EnvVars,
  defaultValue?: string,
  env?: EnvOverrides
): string

export function getEnvBool(
  key: keyof EnvVars,
  defaultValue?: boolean,
  env?: EnvOverrides
): boolean

export function getEnvInt(
  key: keyof EnvVars,
  defaultValue?: number,
  env?: EnvOverrides
): number

export function getEnvFloat(
  key: keyof EnvVars,
  defaultValue?: number,
  env?: EnvOverrides
): number

export function isCI(): boolean

Import

import { getEnvString, getEnvBool, getEnvInt, getEnvFloat, isCI } from './envars';

I/O Contract

Inputs

Name Type Required Description
key keyof EnvVars Yes Environment variable name (type-checked)
defaultValue string/boolean/number No Fallback if variable is unset
env EnvOverrides No Provider-specific overrides object

Outputs

Name Type Description
value string/boolean/number Parsed environment variable value or default

Usage Examples

import { getEnvString, getEnvBool, getEnvInt } from './envars';

// Read API key with no default
const apiKey = getEnvString('OPENAI_API_KEY');

// Check feature flag with default
const cacheEnabled = getEnvBool('PROMPTFOO_CACHE_ENABLED', true);

// Get concurrency limit
const maxConcurrency = getEnvInt('PROMPTFOO_MAX_CONCURRENCY', 4);

// Check if running in CI
import { isCI } from './envars';
if (isCI()) {
  // Adjust behavior for CI environments
}

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment