lfnovo/open-notebook · error · HTTPException

Error fetching default models: {str(e)}

Error message

Error fetching default models: {str(e)}

What it means

Generic 500 from GET /api/v1/models/defaults when reading the default-model assignments fails unexpectedly. Domain errors are re-raised; this branch wraps anything else (DB failure, deserialization of the defaults record).

Source

Thrown at api/routers/models.py:328

    try:
        defaults = await DefaultModels.get_instance()

        return DefaultModelsResponse(
            default_chat_model=defaults.default_chat_model,  # type: ignore[attr-defined]
            default_transformation_model=defaults.default_transformation_model,  # type: ignore[attr-defined]
            large_context_model=defaults.large_context_model,  # type: ignore[attr-defined]
            default_text_to_speech_model=defaults.default_text_to_speech_model,  # type: ignore[attr-defined]
            default_speech_to_text_model=defaults.default_speech_to_text_model,  # type: ignore[attr-defined]
            default_embedding_model=defaults.default_embedding_model,  # type: ignore[attr-defined]
            default_tools_model=defaults.default_tools_model,  # type: ignore[attr-defined]
        )
    except HTTPException:
        raise
    except OpenNotebookError:
        raise
    except Exception as e:
        logger.error(f"Error fetching default models: {str(e)}")
        raise HTTPException(
            status_code=500, detail=f"Error fetching default models: {str(e)}"
        )


# Defaults the app cannot function without — they can be reassigned but
# never cleared (the optional ones fall back to the chat default or are
# simply skipped when unset).
REQUIRED_DEFAULTS = {"default_chat_model", "default_embedding_model"}


@router.put("/models/defaults", response_model=DefaultModelsResponse)
async def update_default_models(defaults_data: DefaultModelsResponse):
    """Update default model assignments.

    Partial-update semantics keyed on field PRESENCE, not value: a field
    absent from the payload is left untouched, while an explicit null clears
    the default (except required ones). `is not None` checks would silently
    ignore a null sent to clear a default — the old value survived while the

View on GitHub (pinned to a7de90d38a)

Solutions

  1. Check API logs for 'Error fetching default models'
  2. Ensure migrations ran on API startup (make api logs)
  3. Restart the API/DB stack in order (database → api)
  4. If the defaults record is corrupted, recreate it via the app UI or API
Defensive patterns

Strategy: retry

Validate before calling

await fetch('/api/v1/health').then(r => { if (!r.ok) throw new Error('API unhealthy'); });

Try / catch

try { const d = await api.getDefaultModels(); } catch (e) { if (e.status === 500) showRetry('Defaults unavailable'); }

Prevention

When it happens

Trigger: Calling GET /models/defaults when SurrealDB is unavailable or the stored defaults record is corrupted/has unknown fields.

Common situations: First run before migrations completed; DB restarted mid-request; schema drift after upgrade.

Related errors


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