{"record":{"id":"204c0940dd6e5973","repo":"lfnovo/open-notebook","slug":"error-fetching-models-str-e","errorCode":null,"errorMessage":"Error fetching models: {str(e)}","messagePattern":"Error fetching models: (.+?)","errorType":"http","errorClass":"HTTPException","httpStatus":500,"severity":"error","filePath":"api/routers/models.py","lineNumber":202,"sourceCode":"        return [\n            ModelResponse(\n                id=model.id,\n                name=model.name,\n                provider=model.provider,\n                type=model.type,\n                credential=model.credential,\n                created=str(model.created),\n                updated=str(model.updated),\n            )\n            for model in models\n        ]\n    except HTTPException:\n        raise\n    except OpenNotebookError:\n        raise\n    except Exception as e:\n        logger.error(f\"Error fetching models: {str(e)}\")\n        raise HTTPException(status_code=500, detail=f\"Error fetching models: {str(e)}\")\n\n\n@router.post(\"/models\", response_model=ModelResponse)\nasync def create_model(model_data: ModelCreate):\n    \"\"\"Create a new model configuration.\"\"\"\n    try:\n        # Validate model type\n        valid_types = [\"language\", \"embedding\", \"text_to_speech\", \"speech_to_text\"]\n        if model_data.type not in valid_types:\n            raise HTTPException(\n                status_code=400,\n                detail=f\"Invalid model type. Must be one of: {valid_types}\",\n            )\n\n        # Check for duplicate model name under the same provider and type (case-insensitive)\n        from open_notebook.database.repository import repo_query\n\n        existing = await repo_query(","sourceCodeStart":184,"sourceCodeEnd":220,"githubUrl":"https://github.com/lfnovo/open-notebook/blob/a7de90d38aaf18ee85fd661854d35c11e44613e2/api/routers/models.py#L184-L220","documentation":"Generic 500 raised by GET /api/v1/models when listing model configs fails unexpectedly. It is the catch-all branch after HTTPException and OpenNotebookError were re-raised, so any non-domain exception (DB down, import error) surfaces here with the underlying message embedded.","triggerScenarios":"Calling GET /models when SurrealDB is unreachable, when the Model class query fails, or when provider introspection throws a non-OpenNotebookError exception.","commonSituations":"SurrealDB not started (make database), wrong DB credentials, or a model provider SDK raising an unexpected exception during listing.","solutions":["Check the API logs for the logged 'Error fetching models' line to see the real exception","Verify SurrealDB is running and reachable (make status / make database)","Verify OPEN_NOTEBOOK_DB settings and restart make api","If the inner exception points to a provider SDK, fix the provider configuration/env keys"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"const health = await fetch('/api/v1/health').then(r=>r.ok); // or check /models with a tiny HEAD-ish GET before heavy listing\nif (!health) throw new Error('API/DB unavailable');","typeGuard":null,"tryCatchPattern":"try { const models = await api.getModels(); } catch (e) { if (e.status === 500) showFatal('Model listing failed: ' + e.detail); else throw e; }","preventionTips":["Keep SurrealDB running (make database) before the API","Monitor API logs for 'Error fetching models'","Use health checks before bulk UI loads"],"tags":["models","http-500","database"],"backgroundTag":"internal-server-error","analyzedSha":"a7de90d38aaf18ee85fd661854d35c11e44613e2","analyzedAt":"2026-08-27T02:39:58.166Z","schemaVersion":2},"datasetVersion":"2026-08-27T03:17:27.898Z"}