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.

feat: Add xAI Grok LLM provider support

LearningCircuitbe1bdfcbc3f8
diff --git a/src/local_deep_research/defaults/llm_providers/xai_settings.json b/src/local_deep_research/defaults/llm_providers/xai_settings.json
new file mode 100644
index 0000000000..e13dfa29f2
--- /dev/null
+++ b/src/local_deep_research/defaults/llm_providers/xai_settings.json
@@ -0,0 +1,16 @@
+{
+ "llm.xai.api_key": {
+ "category": "llm_general",
+ "description": "API key to use for the xAI Grok provider.",
+ "editable": true,
+ "max_value": null,
+ "min_value": null,
+ "name": "xAI API Key",
+ "options": null,
+ "step": null,
+ "type": "SEARCH",
+ "ui_element": "password",
+ "value": null,
+ "visible": true
+ }
+}
diff --git a/src/local_deep_research/llm/providers/__init__.py b/src/local_deep_research/llm/providers/__init__.py
index 2dfcc80c28..673bd3f23e 100644
--- a/src/local_deep_research/llm/providers/__init__.py
+++ b/src/local_deep_research/llm/providers/__init__.py
@@ -2,14 +2,17 @@
from .google import register_google_provider
from .openrouter import register_openrouter_provider
+from .xai import register_xai_provider
from .openai_base import GenericOpenAIEndpoint
__all__ = [
"register_google_provider",
"register_openrouter_provider",
+ "register_xai_provider",
"GenericOpenAIEndpoint",
]
# Auto-register providers on import
register_google_provider()
register_openrouter_provider()
+register_xai_provider()
diff --git a/src/local_deep_research/llm/providers/xai.py b/src/local_deep_research/llm/providers/xai.py
new file mode 100644
index 0000000000..245741edc2
--- /dev/null
+++ b/src/local_deep_research/llm/providers/xai.py
@@ -0,0 +1,72 @@
+"""xAI Grok LLM provider for Local Deep Research."""
+
+from loguru import logger
+
+from ..llm_registry import register_llm
+from .openai_base import OpenAICompatibleProvider
+
+
+class XAIProvider(OpenAICompatibleProvider):
+ """xAI Grok provider using OpenAI-compatible endpoint.
+
+ This uses xAI's OpenAI-compatible API endpoint to access Grok models.
+ """
+
+ provider_name = "xAI Grok"
+ api_key_setting = "llm.xai.api_key"
+ default_base_url = "https://api.x.ai/v1"
+ default_model = "grok-beta"
+
+ @classmethod
+ def requires_auth_for_models(cls):
+ """xAI requires authentication for listing models."""
+ return True
+
+ @classmethod
+ def list_models_for_api(cls, api_key=None):
+ """List available models for xAI.
+
+ xAI requires authentication for the /models endpoint.
+ """
+ if not api_key or api_key.strip() == "":
+ logger.debug("xAI requires API key for listing models")
+ return []
+
+ # Use the parent class implementation which handles the OpenAI-compatible endpoint
+ return super().list_models_for_api(api_key)
+
+
+# Keep the standalone functions for backward compatibility and registration
+def create_xai_llm(model_name=None, temperature=0.7, **kwargs):
+ """Factory function for xAI Grok LLMs using OpenAI-compatible endpoint.
+
+ Args:
+ model_name: Name of the model to use (e.g., "grok-beta", "grok-2", "grok-2-mini")
+ temperature: Model temperature (0.0-1.0)
+ **kwargs: Additional arguments including settings_snapshot
+
+ Returns:
+ A configured ChatOpenAI instance pointing to xAI's API
+
+ Raises:
+ ValueError: If xAI API key is not configured
+ """
+ return XAIProvider.create_llm(model_name, temperature, **kwargs)
+
+
+def is_xai_available(settings_snapshot=None):
+ """Check if xAI Grok is available.
+
+ Args:
+ settings_snapshot: Optional settings snapshot to use
+
+ Returns:
+ True if xAI API key is configured, False otherwise
+ """
+ return XAIProvider.is_available(settings_snapshot)
+
+
+def register_xai_provider():
+ """Register the xAI Grok provider with the LLM registry."""
+ register_llm("xai", create_xai_llm)
+ logger.info("Registered xAI Grok LLM provider")
diff --git a/src/local_deep_research/web/routes/settings_routes.py b/src/local_deep_research/web/routes/settings_routes.py
index 930d45f566..512a275d65 100644
--- a/src/local_deep_research/web/routes/settings_routes.py
+++ b/src/local_deep_research/web/routes/settings_routes.py
@@ -940,6 +940,7 @@ def api_get_available_models():
{"value": "ANTHROPIC", "label": "Anthropic (Cloud)"},
{"value": "GOOGLE", "label": "Google Gemini (Cloud)"},
{"value": "OPENROUTER", "label": "OpenRouter (Cloud)"},
+ {"value": "XAI", "label": "xAI Grok (Cloud)"},
{"value": "OPENAI_ENDPOINT", "label": "Custom OpenAI Endpoint"},
{"value": "VLLM", "label": "vLLM (Local)"},
{"value": "LMSTUDIO", "label": "LM Studio (Local)"},
@@ -1425,6 +1426,40 @@ def api_get_available_models():
providers["openrouter_models"] = openrouter_models
logger.info(f"Final OpenRouter models count: {len(openrouter_models)}")
+ # Try to get xAI models using the provider class
+ xai_models = []
+ try:
+ logger.info("Fetching xAI Grok models")
+
+ from ...llm.providers.xai import XAIProvider
+
+ # Get API key if configured (xAI requires it for listing models)
+ api_key = _get_setting_from_session("llm.xai.api_key", "")
+
+ # Use the provider's list_models_for_api method
+ models = XAIProvider.list_models_for_api(api_key)
+
+ # Format models for the API response
+ for model in models:
+ xai_models.append(
+ {
+ "value": model["value"],
+ "label": f"{model['label']} (xAI)",
+ "provider": "XAI",
+ }
+ )
+
+ logger.info(
+ f"Successfully fetched {len(xai_models)} models from xAI"
+ )
+
+ except Exception as e:
+ logger.exception(f"Error getting xAI models: {e!s}")
+
+ # Set xai_models in providers
+ providers["xai_models"] = xai_models
+ logger.info(f"Final xAI models count: {len(xai_models)}")
+
# Save fetched models to database cache
if force_refresh or providers:
# We fetched fresh data, save it to database