@@ -369,6 +369,21 @@ public struct SearchOptions: Sendable {
369369 /// ```
370370 public let caseSensitive : Bool
371371
372+ /// A required API key for enabling AI-powered search algorithms, such as GPT-based semantic search.
373+ ///
374+ /// This key must be provided when using any search strategy that relies on external AI services.
375+ /// If the key is missing and an AI-based algorithm is selected (e.g., `GPTSemanticSearchAlgorithm`),
376+ /// an error will be thrown or the search will fail.
377+ ///
378+ /// - Important: This is mandatory for semantic searches. Omitting it while using AI algorithms
379+ /// will result in runtime errors or degraded functionality.
380+ ///
381+ /// - Example:
382+ /// ```swift
383+ /// let options = SearchOptions(apiKey: "sk-...")
384+ /// ```
385+ public let apiKey : String ?
386+
372387 /// Enables approximate (fuzzy) matching for file name searches
373388 ///
374389 /// When `true` (default), file name searches will use Levenshtein distance
@@ -464,6 +479,7 @@ public struct SearchOptions: Sendable {
464479 /// - Returns: A configured SearchOptions instance
465480 public init (
466481 caseSensitive: Bool = false ,
482+ apiKey: String ? = ProcessInfo . processInfo. environment [ " OPENAI_API_KEY " ] ,
467483 fuzzyMatching: Bool = true ,
468484 semantic: Bool = false ,
469485 patternMatch: Bool = false ,
@@ -473,6 +489,7 @@ public struct SearchOptions: Sendable {
473489 timeout: TimeInterval ? = nil
474490 ) {
475491 self . caseSensitive = caseSensitive
492+ self . apiKey = apiKey
476493 self . fuzzyMatching = fuzzyMatching
477494 self . semantic = semantic
478495 self . patternMatch = patternMatch
0 commit comments