- Check them at startup -
check_settings - How a value is read - the order and the errors
- Every variable - SLNG, Langfuse, Logfire, Coval
- Flag variables -
env_flag - A variable whose name comes from config -
env_value - Your own settings - subclass
EnvSettings - Every argument these functions take - signatures
Check them at startup
agent.py
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
- A value passed to the constructor wins.
SlngSettings(model="m")ignoresSLNG_MODEL. - Otherwise the class reads the environment. An empty variable counts as unset.
- A
.envfile is read only when you ask:SlngSettings(_env_file=".env"). - The settings feed a
RouterModelCallor a sink. Secrets areSecretStr, so they never show in a log line orrepr. - A missing or bad value raises an error that names every variable to fix. Each class raises its own subclass of
SettingsError:SlngConfigErrororTelemetryConfigError.
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 usesenv_valuebelow. Likecredential_env, it reads the exact name, in the case you wrote it.save_call_startreadsUNMUTE_CALL_START, a JSON object like{"customer_id": "c_42"}, for a local run. The dispatch’s values win over it, andenv=Falseskips it. See start values. A value that is not a JSON object raisesSettingsError.KnowledgeBase(credential_env=...)reads its embedding key when it starts.
OTEL_EXPORTER_OTLP_* for the Otlp sink itself.
Flag variables
env_flag reads a variable that turns something on or off:
1,true,yes,y,onandtmean on.0,false,no,n,offandfmean off. Case and spaces around the value do not matter.- An unset or empty variable gives
default, which isFalseunless you pass one. - Any other word raises
SettingsErrorand 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
env_value(name, kind)reads one variable and returns it as akind.- An unset or empty variable gives
None. - A value that is not a
kindraisesSettingsError. - Use it when the name is your own config, like a webhook’s
token_env. Use a settings class when the name is fixed. - The name is read exactly, and case matters.
orders_tokendoes not answerORDERS_TOKEN. The same holds fortoken_envandcredential_env.
Your own settings
SubclassEnvSettings 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.