Skip to main content
Each part of the library that needs a key or a URL reads it through one settings class. Load them once at startup, so a missing key fails the deploy and not the first call. On this page:

Check them at startup

agent.py
If SHOP_OPENAI_API_KEY and LANGFUSE_SECRET_KEY are unset, check_settings raises one SettingsError that names both. The error lists every missing variable, so one deploy fixes them all. The library’s own classes work the same way. LangfuseSettings above is one. SlngSettings holds the variables of the SLNG Context Router. This is a router call with your own OpenAI key:
router.py
RouterSettings adds your OpenAI key to the SLNG settings. Each request carries your own router config with that key. See Your router config.

How a value is read

  1. A value passed to the constructor wins. SlngSettings(model="m") ignores SLNG_MODEL.
  2. Otherwise the class reads the environment. An empty variable counts as unset.
  3. A .env file is read only when you ask: SlngSettings(_env_file=".env").
  4. The settings feed a RouterModelCall or a sink. Secrets are SecretStr, so they never show in a log line or repr.
  5. A missing or bad value raises an error that names every variable to fix. Each class raises its own subclass of SettingsError: SlngConfigError or TelemetryConfigError.
Nothing reads the environment when you import the library.

Every variable

Copy this into your .env.example. A line that starts with # has a default.
env_example(SlngSettings, LangfuseSettings, ...) prints the same text for the classes your app uses. A test keeps this block in step with the classes. The SLNG variables feed the optional Context Router model call. The Langfuse, Logfire and Coval variables feed the telemetry sinks. Some names are yours to pick, and the library reads them when it needs them, not through a settings class:
  • WebhookAuth(token_env=...) reads its token on each webhook call, so a rotated token works without a restart. It uses env_value below. Like credential_env, it reads the exact name, in the case you wrote it.
  • save_call_start reads UNMUTE_CALL_START, a JSON object like {"customer_id": "c_42"}, for a local run. The dispatch’s values win over it, and env=False skips it. See start values. A value that is not a JSON object raises SettingsError.
  • KnowledgeBase(credential_env=...) reads its embedding key when it starts.
The OpenTelemetry SDK reads OTEL_EXPORTER_OTLP_* for the Otlp sink itself.

Flag variables

env_flag reads a variable that turns something on or off:
  1. 1, true, yes, y, on and t mean on. 0, false, no, n, off and f mean off. Case and spaces around the value do not matter.
  2. An unset or empty variable gives default, which is False unless you pass one.
  3. Any other word raises SettingsError and names the variable. The library does not guess.
UNMUTE_DEV_METRICS, which turns on dev records, reads the same words. A word it does not know logs a warning and counts as off, so a typo never breaks a call.

A variable whose name comes from config

  1. env_value(name, kind) reads one variable and returns it as a kind.
  2. An unset or empty variable gives None.
  3. A value that is not a kind raises SettingsError.
  4. Use it when the name is your own config, like a webhook’s token_env. Use a settings class when the name is fixed.
  5. The name is read exactly, and case matters. orders_token does not answer ORDERS_TOKEN. The same holds for token_env and credential_env.

Your own settings

Subclass EnvSettings to get the same behaviour for your app’s own names:
check_settings(SlngSettings, SalonSettings) then names SALON_BOOKING_API_KEY with the rest.

Every argument these functions take

check_settings

type[EnvSettings]
required
The settings classes the app needs, like SlngSettings. Returns one loaded object per class, in order. Raises SettingsError if any class is missing a value or holds a bad one.

env_flag

str
required
The variable to read, like UNMUTE_LOCAL_RUN.
bool
default:"False"
The value when the variable is unset or empty. Keyword only.

env_value

str
required
The variable to read, like ORDERS_TOKEN.
type
required
The type to read it as, like str or int. Returns a kind, or None when the variable is unset or empty. Raises SettingsError when the value is not a kind.

env_example

type[EnvSettings]
required
The settings classes to print. Each variable gets its field description as a comment. A required variable is left empty, and one with a default shows it commented out.

Where to go next

SLNG

What the SLNG variables do in the Context Router call.

Telemetry

The sinks that read the Langfuse, Logfire and Coval variables.