"""Centralized application configuration via pydantic-settings.""" from __future__ import annotations from typing import Literal from pydantic import model_validator from pydantic_settings import BaseSettings, SettingsConfigDict class Settings(BaseSettings): model_config = SettingsConfigDict( env_file=".env", env_file_encoding="utf-8", extra="ignore", ) database_url: str llm_provider: Literal["anthropic", "openai", "azure_openai", "google"] = "anthropic" llm_model: str = "claude-sonnet-4-6" session_ttl_minutes: int = 30 interrupt_ttl_minutes: int = 30 ws_host: str = "0.0.0.0" ws_port: int = 8000 webhook_url: str = "" webhook_timeout_seconds: int = 10 webhook_max_retries: int = 3 template_name: str = "" log_format: str = "console" # "console" for dev, "json" for production admin_api_key: str = "" anthropic_api_key: str = "" openai_api_key: str = "" azure_openai_api_key: str = "" azure_openai_endpoint: str = "" azure_openai_api_version: str = "2024-12-01-preview" azure_openai_deployment: str = "" google_api_key: str = "" @model_validator(mode="after") def validate_provider_key(self) -> Settings: key_map = { "anthropic": self.anthropic_api_key, "openai": self.openai_api_key, "azure_openai": self.azure_openai_api_key, "google": self.google_api_key, } key = key_map.get(self.llm_provider, "") if not key: raise ValueError( f"API key for provider '{self.llm_provider}' is required. " f"Set the corresponding environment variable." ) if self.llm_provider == "azure_openai": if not self.azure_openai_endpoint: raise ValueError( "AZURE_OPENAI_ENDPOINT is required for azure_openai provider." ) if not self.azure_openai_deployment: raise ValueError( "AZURE_OPENAI_DEPLOYMENT is required for azure_openai provider." ) return self