khoj-ai/khoj · critical · ValueError
Invalid conversation settings. Configure some chat model on
Error message
Invalid conversation settings. Configure some chat model on server.
What it means
ConversationAdapters.get_chat_model (or sibling chat-model resolution) raises ValueError when the stored chat model config does not match any supported provider (offline/OpenAI/Anthropic/Google) or lacks an ai_model_api reference. It means the server's chat model configuration is unusable.
Source
Thrown at src/khoj/database/adapters/__init__.py:1752
)
else:
chat_model = await ConversationAdapters.aget_chat_model(user)
if chat_model is None:
chat_model = await ConversationAdapters.aget_default_chat_model()
if (
chat_model.model_type
in [
ChatModel.ModelType.ANTHROPIC,
ChatModel.ModelType.OPENAI,
ChatModel.ModelType.GOOGLE,
]
) and chat_model.ai_model_api:
return chat_model
else:
raise ValueError("Invalid conversation settings. Configure some chat model on server.")
@staticmethod
async def aget_text_to_image_model_config():
return await TextToImageModelConfig.objects.filter().prefetch_related("ai_model_api").afirst()
@staticmethod
def get_text_to_image_model_config():
return TextToImageModelConfig.objects.filter().first()
@staticmethod
def get_text_to_image_model_options():
return TextToImageModelConfig.objects.all()
@staticmethod
def get_user_text_to_image_model_config(user: KhojUser):
config = UserTextToImageModelConfig.objects.filter(user=user).first()
if not config:
default_config = ConversationAdapters.get_text_to_image_model_config()View on GitHub (pinned to ae229ca894)
Solutions
- Open server admin config and (re)configure a valid chat model (e.g. set a default model with its AI model API key/endpoint).
- Verify the ChatModelConfig row's model_type is one of the supported provider values and ai_model_api is set.
- If upgrading khoj, re-run setup/migrations so default chat model options are seeded.
Example fix
# before chat_model = ConversationAdapters.get_chat_model() # ValueError # after from khoj.database.adapters import ConversationAdapters from khoj.database.models import ChatModel, AiModelApi api, _ = AiModelApi.objects.get_or_create(api_key=API_KEY, name="OpenAI") ChatModel.objects.get_or_create(name="gpt-4o", model_type=ChatModel.ModelType.OPENAI, ai_model_api=api) chat_model = ConversationAdapters.get_chat_model()
Defensive patterns
Strategy: fallback
Validate before calling
from khoj.database.models import ChatModel, AiModelApi
def chat_model_configured() -> bool:
return ChatModel.objects.exclude(ai_model_api=None).exists() and AiModelApi.objects.exists()
if not chat_model_configured():
# run setup wizard / admin config before serving chat Try / catch
try:
chat_model = ConversationAdapters.get_chat_model()
except ValueError as e:
if "Configure some chat model" in str(e):
return JSONResponse({"detail": "Server chat model not configured"}, status_code=503)
raise Prevention
- Complete server setup (admin panel) before exposing chat endpoints.
- After upgrades, verify ChatModelConfig rows have valid model_type and ai_model_api.
- Add a startup health check that a usable chat model resolves.
When it happens
Trigger: ChatModelConfig row with an unexpected model_type, or a row whose ai_model_api_id is null; also when no default chat model is configured at all and fallback resolution fails.
Common situations: Fresh installs without a configured chat model; DB rows edited manually or left behind by older khoj versions; API key config deleted while the model row remains.
Related errors
- A public Agent with the name {instance.name} already exists.
- A private Agent with the name {instance.name} already exists
- Invalid conversation_log format: {str(e)}
- An Entry cannot be associated with both a user and an agent.
- Invalid automation id: {automation_id}
AI-assisted analysis of khoj-ai/khoj@ae229ca894 (2026-08-27).
Data as JSON: /api/errors/02cb92fbb77fad86.
Report an issue: GitHub.