lfnovo/open-notebook · warning · HTTPException

Model not found

Error message

Model not found

What it means

404 from DELETE /api/v1/models/{model_id} when the repository raises NotFoundError, i.e. no model with that id exists (or it was already deleted). It is also the fallback mapping when Model.get inside delete fails to find the record.

Source

Thrown at api/routers/models.py:274

        raise
    except Exception as e:
        logger.error(f"Error creating model: {str(e)}")
        raise HTTPException(status_code=500, detail=f"Error creating model: {str(e)}")


@router.delete("/models/{model_id}")
async def delete_model(model_id: str):
    """Delete a model configuration."""
    try:
        model = await Model.get(model_id)

        await model.delete()

        return {"message": "Model deleted successfully"}
    except HTTPException:
        raise
    except NotFoundError:
        raise HTTPException(status_code=404, detail="Model not found")
    except OpenNotebookError:
        raise
    except Exception as e:
        logger.error(f"Error deleting model {model_id}: {str(e)}")
        raise HTTPException(status_code=500, detail=f"Error deleting model: {str(e)}")


@router.post("/models/{model_id}/test", response_model=ModelTestResponse)
async def test_model(model_id: str):
    """Test if a specific model is correctly configured and functional."""
    try:
        model = await Model.get(model_id)
        if not model:
            raise HTTPException(status_code=404, detail="Model not found")
    except HTTPException:
        raise
    except OpenNotebookError:
        raise

View on GitHub (pinned to a7de90d38a)

Solutions

  1. Refresh the model list and use current ids
  2. Treat 404 on delete as success (idempotent delete) in the client
  3. If the model should exist, verify you're pointing at the right API instance/database

Example fix

// before
if (res.status !== 200) throw new Error('delete failed');
// after
if (res.status === 404) return; // already gone — treat as deleted
if (!res.ok) throw new Error(await res.text());
Defensive patterns

Strategy: try-catch

Validate before calling

const exists = (await api.getModels()).some(m => m.id === modelId);
if (!exists) return; // nothing to delete

Try / catch

try { await api.deleteModel(id); } catch (e) { if (e.status === 404) return; // idempotent success
 throw e; }

Prevention

When it happens

Trigger: DELETE /models/{id} with a stale id, an id from another instance, or calling delete twice.

Common situations: UI holding a stale list after another tab/session deleted the model, or ids copied between environments.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


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