{"record":{"id":"b1e5538289072e07","repo":"lfnovo/open-notebook","slug":"error-creating-model-str-e","errorCode":null,"errorMessage":"Error creating model: {str(e)}","messagePattern":"Error creating model: (.+?)","errorType":"http","errorClass":"HTTPException","httpStatus":500,"severity":"error","filePath":"api/routers/models.py","lineNumber":259,"sourceCode":"\n        return ModelResponse(\n            id=new_model.id or \"\",\n            name=new_model.name,\n            provider=new_model.provider,\n            type=new_model.type,\n            credential=new_model.credential,\n            created=str(new_model.created),\n            updated=str(new_model.updated),\n        )\n    except HTTPException:\n        raise\n    except InvalidInputError as e:\n        raise HTTPException(status_code=400, detail=str(e))\n    except OpenNotebookError:\n        raise\n    except Exception as e:\n        logger.error(f\"Error creating model: {str(e)}\")\n        raise HTTPException(status_code=500, detail=f\"Error creating model: {str(e)}\")\n\n\n@router.delete(\"/models/{model_id}\")\nasync def delete_model(model_id: str):\n    \"\"\"Delete a model configuration.\"\"\"\n    try:\n        model = await Model.get(model_id)\n\n        await model.delete()\n\n        return {\"message\": \"Model deleted successfully\"}\n    except HTTPException:\n        raise\n    except NotFoundError:\n        raise HTTPException(status_code=404, detail=\"Model not found\")\n    except OpenNotebookError:\n        raise\n    except Exception as e:","sourceCodeStart":241,"sourceCodeEnd":277,"githubUrl":"https://github.com/lfnovo/open-notebook/blob/a7de90d38aaf18ee85fd661854d35c11e44613e2/api/routers/models.py#L241-L277","documentation":"Generic 500 from POST /api/v1/models when model creation fails with an unexpected exception. InvalidInputError is mapped to 400 and OpenNotebookError is re-raised; anything else (DB failure, constructor error in Model) lands here.","triggerScenarios":"POST /models with an otherwise-valid body while SurrealDB is down or the Model constructor throws (e.g. malformed provider config object).","commonSituations":"DB connection dropped mid-request, missing required fields that bypass Pydantic validation, or unexpected type in model_data.","solutions":["Read the API log line 'Error creating model: ...' for the root cause","Verify DB connectivity and retry","Check that all ModelCreate fields match expected types/shapes","If caused by [82]'s race (duplicate created between check and insert), handle the unique-constraint error explicitly"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"await assertDbHealthy(); // GET /api/v1/health before create","typeGuard":null,"tryCatchPattern":"try { await api.createModel(data); } catch (e) { if (e.status === 500) { log(e.detail); await retryOnce(); } else throw e; }","preventionTips":["Verify DB connectivity before write operations","Validate payload shape client-side","Check logs for the embedded root-cause message"],"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"}