lfnovo/open-notebook · error · HTTPException

Error updating default models: {str(e)}

Error message

Error updating default models: {str(e)}

What it means

Generic 500 from PATCH /api/v1/models/defaults when updating default assignments fails unexpectedly. Domain errors (including InvalidInputError → 400) are re-raised; this wraps DB write failures or unexpected errors during defaults.update().

Source

Thrown at api/routers/models.py:382

        # No cache refresh needed - next access will fetch fresh data from DB

        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 updating default models: {str(e)}")
        raise HTTPException(
            status_code=500, detail=f"Error updating default models: {str(e)}"
        )


@router.get("/models/providers", response_model=ProviderAvailabilityResponse)
async def get_provider_availability():
    """Get provider availability based on database config and environment variables."""
    try:
        # Check which providers have credentials in the database or env vars
        # For each provider, check DB credentials first, then env vars as fallback

        # Simple env var mapping for backward compatibility
        env_var_map = {
            "openai": "OPENAI_API_KEY",
            "anthropic": "ANTHROPIC_API_KEY",
            "google": "GOOGLE_API_KEY",
            "groq": "GROQ_API_KEY",
            "mistral": "MISTRAL_API_KEY",

View on GitHub (pinned to a7de90d38a)

Solutions

  1. Check API logs for 'Error updating default models'
  2. Verify every model id in the body exists (GET /models) before assigning
  3. Verify DB connectivity and retry the update
Defensive patterns

Strategy: validation

Validate before calling

const models = await api.getModels();
const ids = new Set(models.map(m => m.id));
for (const [k,v] of Object.entries(patch)) if (v && !ids.has(v)) throw new Error(`${k}: unknown model ${v}`);

Try / catch

try { await api.updateDefaults(patch); } catch (e) { if (e.status === 500) { checkLogs(); await retry(); } }

Prevention

When it happens

Trigger: PATCH /models/defaults referencing a model id that fails on update, or while SurrealDB is down.

Common situations: Assigning a default to a model that was just deleted in another session; DB outage; concurrency conflict on the defaults record.

Related errors


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