lfnovo/open-notebook · error · HTTPException

Error executing chat: {str(e)}

Error message

Error executing chat: {str(e)}

What it means

500 from POST /chat/execute when the AI chat pipeline throws an unexpected exception. The handler logs session id, model override, and full traceback, then surfaces the message in the 500 detail.

Source

Thrown at api/routers/chat.py:388

        # Convert messages to response format
        messages = extract_chat_messages(result.get("messages", []))

        return ExecuteChatResponse(session_id=request.session_id, messages=messages)
    except NotFoundError:
        raise HTTPException(status_code=404, detail="Session not found")
    except HTTPException:
        raise
    except OpenNotebookError:
        raise
    except Exception as e:
        # Log detailed error with context for debugging
        logger.error(
            f"Error executing chat: {str(e)}\n"
            f"  Session ID: {request.session_id}\n"
            f"  Model override: {request.model_override}\n"
            f"  Traceback:\n{traceback.format_exc()}"
        )
        raise HTTPException(status_code=500, detail=f"Error executing chat: {str(e)}")


@router.post("/chat/context", response_model=BuildContextResponse)
async def build_context(request: BuildContextRequest):
    """Build context for a notebook based on context configuration."""
    try:
        # Verify notebook exists
        notebook = await Notebook.get(request.notebook_id)
        if not notebook:
            raise HTTPException(status_code=404, detail="Notebook not found")

        context_data, total_content = await build_notebook_context(
            notebook, request.context_config
        )

        char_count = len(total_content)
        estimated_tokens = token_count(total_content) if total_content else 0

View on GitHub (pinned to a7de90d38a)

Solutions

  1. Read the API log — the full traceback and session/model context are printed
  2. Verify a default chat model is set and provider credentials are valid (check /api/providers and credentials endpoints)
  3. Test with a smaller notebook context and an explicit model_override to isolate provider issues
  4. Confirm the surreal-commands worker is running if the pipeline enqueues jobs
Defensive patterns

Strategy: try-catch

Validate before calling

const providers = await (await fetch('/api/providers')).json();
if (!providers.some(p => p.id === modelId)) throw new Error('Model not available');

Try / catch

catch (e) { if (e.status === 500) showModelConfigHint(); logToConsole(e.detail); throw e; }

Prevention

When it happens

Trigger: Missing/unconfigured AI provider credentials (no default model set), model API rate limits or auth failures inside the graph invocation, or context-building failures for the notebook's sources.

Common situations: No default model configured in settings; OpenAI/Anthropic API key invalid or expired; embeddings model unreachable; oversized context exceeding provider limits.

Related errors


AI-assisted analysis of lfnovo/open-notebook@a7de90d38a (2026-08-27). Data as JSON: /api/errors/85c56946573ff53f. Report an issue: GitHub.