TL;DR
- Providers (LLMs, Cloudinary, Redis clients, etc.) are initialized only when first used.
- If required envs are missing in dev: we warn and return
Noneso the feature is simply unavailable. - In production: missing required envs should be treated as errors.
The rules
- Env values live in
settings(backend/app/config/settings.py). - Register providers with
@lazy_provider(...)frombackend/app/core/lazy_loader.py. - Declare
required_keys=[...]using values fromsettings. - Choose how to handle missing keys via
strategy:ERROR,WARN,WARN_ONCE,SILENT. - Call
providers.get(name)(sync) orawait providers.aget(name)(async) only when you actually need the provider.
Minimal pattern
Global context (config, not an instance)
Error behavior (quick mental model)
- Dev: prefer
WARN→ feature returnsNoneuntil you add keys. - Prod: prefer
ERROR→ app raisesConfigurationErroron first use if keys are missing/invalid.
References
- Implementation:
backend/app/core/lazy_loader.py - Settings (env parsing):
backend/app/config/settings.py
