Skip to main content
SAFIA is configured through a .env file created during safia setup. You can re-open that file at any time using the interactive editor, or edit it directly with a text editor. All variables below correspond to entries in .env.
safia config
The sections below group every supported variable by function. Variables marked required must be set before SAFIA will start successfully.

Required

These five variables are the minimum needed to run the bot.
VariableDescription
TELEGRAM_BOT_TOKENYour bot’s token from @BotFather.
LLM_PROVIDERThe LLM backend to use: lunos, groq, openai, or custom. Defaults to lunos.
LLM_API_KEYAPI key for the selected LLM provider.
DATABASE_URLSQLAlchemy connection string. Defaults to sqlite+aiosqlite:///data/safia.db.
REDIS_URLRedis connection string. Defaults to redis://localhost:6379/0.
A minimal .env for getting started:
TELEGRAM_BOT_TOKEN=your-telegram-bot-token
LLM_PROVIDER=lunos
LLM_API_KEY=your-api-key
DATABASE_URL=sqlite+aiosqlite:///data/safia.db
REDIS_URL=redis://localhost:6379/0
Never commit your .env file to version control. It contains credentials that grant full access to your bot and LLM account.

LLM Settings

SAFIA supports four LLM providers out of the box. Each provider’s base URL is set automatically — you only need to supply LLM_PROVIDER and LLM_API_KEY.
VariableDefaultDescription
LLM_PROVIDERlunosProvider name: lunos, groq, openai, or custom.
LLM_API_KEYAPI key for the selected provider.
LLM_MODELopenai/gpt-oss-120bModel identifier passed to the provider API.
LLM_BASE_URLBase URL for a custom OpenAI-compatible provider. Required only when LLM_PROVIDER=custom.
VISION_MODELmistralai/mistral-small-3.2-24b-instructModel used for receipt and document photo extraction. Uses the same provider and API key as the chat model.
LLM_PROVIDER=lunos
LLM_API_KEY=your-lunos-api-key
LLM_MODEL=openai/gpt-oss-120b
The Lunos base URL (https://api.lunosrouter.com/v1) is set automatically.
Speech-to-text always uses Whisper via Groq, regardless of which LLM provider you select for chat. If you use a non-Groq LLM provider, set GROQ_API_KEY separately to enable voice message transcription.
Two optional integrations expand what SAFIA can do:
VariableDefaultDescription
GROQ_API_KEYGroq API key for Whisper voice transcription. Required if your LLM_PROVIDER is not groq.
FIRECRAWL_API_KEYAPI key from firecrawl.dev for web search and article fetching. Leave empty to disable web search.
# Optional: enable voice messages when using a non-Groq LLM provider
GROQ_API_KEY=your-groq-api-key

# Optional: enable web search and article fetching
FIRECRAWL_API_KEY=your-firecrawl-api-key

Database & Cache

SAFIA stores all financial data in a relational database and uses Redis for chat history and rate limiting.
VariableDefaultDescription
DATABASE_URLsqlite+aiosqlite:///data/safia.dbSQLAlchemy async connection string. SQLite is zero-config; use a PostgreSQL URL for production deployments.
REDIS_URLredis://localhost:6379/0Redis connection string used for chat history, price caches, and per-user rate limiting.
SQLite (default) — no additional setup required. The database file is created automatically at data/safia.db. PostgreSQL — swap DATABASE_URL with an asyncpg connection string:
DATABASE_URL=postgresql+asyncpg://user:password@localhost:5432/safia
SQLite is the recommended choice for personal use. Switch to PostgreSQL only if you plan to run SAFIA for multiple users concurrently or need point-in-time backups.

Admin Dashboard

The admin dashboard runs at http://127.0.0.1:5454 and provides usage metrics, a user registry, and knowledge base management. Protect it with HTTP Basic Auth before using it.
VariableDefaultDescription
ADMIN_USERNAME(empty)Username for HTTP Basic Auth on the dashboard.
ADMIN_PASSWORD(empty)Password for HTTP Basic Auth on the dashboard.
FLASK_SECRET_KEY(empty)Secret key used by Flask for session signing. Set this to a long random string.
ADMIN_USERNAME=admin
ADMIN_PASSWORD=a-strong-password-here
FLASK_SECRET_KEY=replace-with-a-random-secret-string
If ADMIN_USERNAME and ADMIN_PASSWORD are left empty, the dashboard is accessible without authentication. Always set these before exposing port 5454 beyond localhost.

Knowledge Base

The knowledge base (RAG) lets you upload documents that SAFIA uses to ground its responses. Embeddings and vector storage run locally by default.
VariableDefaultDescription
QDRANT_PATHdata/qdrantOn-disk path for Qdrant vector storage. Used when no QDRANT_URL is set.
QDRANT_URL(empty)URL of a remote Qdrant server. Overrides QDRANT_PATH when set.
QDRANT_API_KEY(empty)API key for an authenticated remote Qdrant instance.
KB_MAX_UPLOAD_MB200Maximum file size (in MB) for knowledge base document uploads.
KB_CHUNK_WORDS450Number of words per document chunk when ingesting files.
KB_CHUNK_OVERLAP_WORDS70Word overlap between consecutive chunks to preserve context.
EMBEDDING_LOCALtrueSet to false to use a remote embedding API instead of local ONNX.
EMBEDDING_LOCAL_MODELsentence-transformers/paraphrase-multilingual-MiniLM-L12-v2Local ONNX embedding model (~120 MB, downloads once).
Optional: Remote Qdrant
QDRANT_URL=http://127.0.0.1:6333
QDRANT_API_KEY=your-qdrant-api-key
Optional: Remote Embeddings
EMBEDDING_LOCAL=false
EMBEDDING_BASE_URL=https://openrouter.ai/api/v1
EMBEDDING_API_KEY=your-key
EMBEDDING_MODEL=openai/text-embedding-3-small
EMBEDDING_VECTOR_SIZE=1536
The local embedding model downloads automatically on first use and runs on CPU via ONNX Runtime. No GPU is required. Switching to remote embeddings is only necessary if your machine has very limited disk space or you want to use a higher-dimensional model.

Reminders

SAFIA can send scheduled reminders for price alerts, news digests, and portfolio summaries.
VariableDefaultDescription
REMINDER_ENABLEDtrueSet to false to disable all scheduled reminders globally.
REMINDER_MAX_PER_USER10Maximum number of active reminders a single user can have at one time.
REMINDER_MAX_SENDS_PER_DAY15Maximum reminder messages sent to a user per day.
REMINDER_TICK_SECONDS30How often (in seconds) the reminder scheduler checks for due reminders.
REMINDER_ENABLED=true
REMINDER_MAX_PER_USER=10
REMINDER_MAX_SENDS_PER_DAY=15

Rate Limiting

SAFIA enforces a daily message limit per user to manage LLM API costs.
VariableDefaultDescription
DAILY_MESSAGE_LIMIT25Maximum number of bot messages a single user can send per day. Resets at midnight.
DAILY_MESSAGE_LIMIT=25
Increase DAILY_MESSAGE_LIMIT if you are the sole user of your SAFIA instance and want unrestricted access. Be mindful of your LLM provider’s rate limits and billing when raising this value.