def __init__(self, base_url: str = "https://google.serper.dev", search_type: str = "search", n_results: int = 10, country: str = "us", 
                 location: str = None, locale: str = "en", api_key: Optional[str] = None):
        """
        Initialize the SerperDev search tool.
        
        Args:
            base_url: Base URL for the Serper API (default: "https://google.serper.dev")
            search_type: Type of search to perform (default: "search")
            n_results: Number of results to return (default: 10)
            country: Country code for search (default: "us")
            location: Location for search (default: None)
            locale: Locale for search (default: "en")
            api_key: Serper API key (optional, will try to load from environment if not provided)
        """
        self.base_url = base_url
        self.search_type = search_type
        self.n_results = n_results
        self.country = country
        self.location = location
        self.locale = locale
        
        # Set API key
        self.api_key = api_key
        
        # If API key not provided, try to load from environment or .env file
        if self.api_key is None:
            # First check environment variables
            if "SERPER_API_KEY" in os.environ:
                self.api_key = os.environ["SERPER_API_KEY"]
            else:
                # Try to load from .env file
                try:
                    api_key = self._load_api_key_from_env_file()
                    if api_key:
                        self.api_key = api_key
                    else:
                        # Print missing API key message
                        missing_api_key("SerperDev", "SERPER_API_KEY")
                        raise EnvironmentError("SERPER_API_KEY environment variable is not set and could not be found in .env file")
                except ImportError:
                    # If dotenv is not installed and no API key in environment
                    if "SERPER_API_KEY" not in os.environ:
                        # Print missing API key message without dotenv support
                        missing_api_key("SerperDev", "SERPER_API_KEY", dotenv_support=False)
                        raise EnvironmentError("SERPER_API_KEY environment variable is not set and python-dotenv is not installed")
                    self.api_key = os.environ["SERPER_API_KEY"]

        Initialize the SerperDev search tool.
        
        Args:
            base_url: Base URL for the Serper API (default: "https://google.serper.dev")
            search_type: Type of search to perform (default: "search")
            n_results: Number of results to return (default: 10)
            country: Country code for search (default: "us")
            location: Location for search (default: None)
            locale: Locale for search (default: "en")
            api_key: Serper API key (optional, will try to load from environment if not provided)
        
src/upsonic/tools.py