Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

debug: add detailed API key lookup logging to create_search_engine

LearningCircuit58c66100162b
diff --git a/.gitleaks.toml b/.gitleaks.toml
index 6835e3d661..5f8822d337 100644
--- a/.gitleaks.toml
+++ b/.gitleaks.toml
@@ -95,6 +95,7 @@ paths = [
'''src/local_deep_research/embeddings/providers/.*\.py$''',
# Web search engines use api_key variable names (not actual secrets)
'''src/local_deep_research/web_search_engines/engines/.*\.py$''',
+ '''src/local_deep_research/web_search_engines/search_engine_factory\.py$''',
# HTML templates use csrfToken variable names (not actual secrets)
'''src/local_deep_research/web/templates/.*\.html$''',
# Notification flow docs contain example code with parameter names
diff --git a/src/local_deep_research/web_search_engines/search_engine_factory.py b/src/local_deep_research/web_search_engines/search_engine_factory.py
index 35f165cc79..c13fceed12 100644
--- a/src/local_deep_research/web_search_engines/search_engine_factory.py
+++ b/src/local_deep_research/web_search_engines/search_engine_factory.py
@@ -153,28 +153,66 @@ def create_search_engine(
kwargs["max_results"] = max_results
# Check for API key requirements
- if engine_config.get("requires_api_key", False):
+ import sys
+
+ requires_api_key = engine_config.get("requires_api_key", False)
+ print(
+ f"[LDR-DEBUG factory] engine_config.requires_api_key={requires_api_key}",
+ file=sys.stderr,
+ )
+
+ if requires_api_key:
# Check the settings snapshot for the API key
api_key = None
+ api_key_path = f"search.engine.web.{engine_name}.api_key"
+ print(
+ f"[LDR-DEBUG factory] Looking for API key at path: {api_key_path}",
+ file=sys.stderr,
+ )
+
if settings_snapshot:
- api_key_setting = settings_snapshot.get(
- f"search.engine.web.{engine_name}.api_key"
+ # Debug: print all keys in settings_snapshot that contain "api_key"
+ api_key_keys = [
+ k for k in settings_snapshot.keys() if "api_key" in k.lower()
+ ]
+ print(
+ f"[LDR-DEBUG factory] API key related keys in settings_snapshot: {api_key_keys}",
+ file=sys.stderr,
+ )
+
+ api_key_setting = settings_snapshot.get(api_key_path)
+ print(
+ f"[LDR-DEBUG factory] api_key_setting from snapshot: {api_key_setting} (type: {type(api_key_setting)})",
+ file=sys.stderr,
)
+
if api_key_setting:
api_key = (
api_key_setting.get("value")
if isinstance(api_key_setting, dict)
else api_key_setting
)
+ print(
+ f"[LDR-DEBUG factory] Extracted api_key: {api_key[:10] if api_key else 'None'}...",
+ file=sys.stderr,
+ )
# Still try to get from engine config if not found
if not api_key:
api_key = engine_config.get("api_key")
+ print(
+ f"[LDR-DEBUG factory] api_key from engine_config: {api_key[:10] if api_key else 'None'}...",
+ file=sys.stderr,
+ )
if not api_key:
logger.info(
f"Required API key for {engine_name} not found in settings."
)
+ print(
+ "[LDR-DEBUG factory] RETURNING None - no API key found",
+ file=sys.stderr,
+ )
return None
# Pass the API key in kwargs for engines that need it