"""Configuration and secrets management. Loads environment variables from .env file for API keys and other secrets. """ import logging import os from dotenv import load_dotenv load_dotenv() # Logging configuration log_level = os.getenv("LOG_LEVEL", "INFO").upper() logging.basicConfig( level=getattr(logging, log_level, logging.INFO), format="%(asctime)s %(levelname)s %(name)s %(message)s", ) # SerpAPI key for patent search api_key = os.getenv("API_KEY") # OpenRouter API key for LLM analysis openrouter_api_key = os.getenv("OPENROUTER_API_KEY") # Database configuration - all messages are stored in the database # The database serves as both a persistent store and a cache layer database_url = os.getenv("DATABASE_URL", "postgresql://postgres:postgres@localhost:5432/sparc") # Cache configuration # When enabled (default), the system checks the database for cached responses # before making API calls, saving tokens and reducing latency use_cache = os.getenv("USE_CACHE", "true").lower() in ("true", "1", "yes") # Legacy compatibility - USE_DATABASE is deprecated, database is always used # This variable is kept for backwards compatibility but has no effect use_database = os.getenv("USE_DATABASE", "false").lower() in ("true", "1", "yes") # Patent search configuration patent_search_days = int(os.getenv("PATENT_SEARCH_DAYS", "90")) patent_thread_workers = int(os.getenv("PATENT_THREAD_WORKERS", "5")) # LLM model to use via OpenRouter (e.g. "anthropic/claude-3.5-sonnet", "openai/gpt-4o") model = os.getenv("MODEL", "anthropic/claude-3.5-sonnet") # SERP cache TTL in hours (how long cached search results are considered fresh) serp_cache_ttl_hours = int(os.getenv("SERP_CACHE_TTL_HOURS", "24")) # Root path for running behind a reverse proxy (e.g., "/api" when served at /api/) # This ensures OpenAPI docs work correctly when accessed via the proxy root_path = os.getenv("ROOT_PATH", "") # Application environment: "development", "staging", or "production" # Used for safety checks (e.g., refusing default JWT secret in production) app_env = os.getenv("APP_ENV", "development") # Storage backend: "local" (default) or "s3" for S3/MinIO object storage storage_backend = os.getenv("STORAGE_BACKEND", "local") s3_bucket = os.getenv("S3_BUCKET", "sparc-patents") s3_endpoint_url = os.getenv("S3_ENDPOINT_URL", "") s3_access_key = os.getenv("AWS_ACCESS_KEY_ID", "") s3_secret_key = os.getenv("AWS_SECRET_ACCESS_KEY", "") # CORS allowed origins (comma-separated) # Defaults to localhost dev origins when unset _cors_origins_raw = os.getenv("CORS_ORIGINS", "") cors_origins: list[str] = ( [o.strip() for o in _cors_origins_raw.split(",") if o.strip()] if _cors_origins_raw else ["http://localhost:3000", "http://localhost:5173"] )