{"record":{"id":"380fd568b292474d","repo":"unslothai/unsloth","slug":"only-trained-or-exported-unsloth-models-can-be-del","errorCode":null,"errorMessage":"Only trained or exported Unsloth models can be deleted","messagePattern":"Only trained or exported Unsloth models can be deleted","errorType":"http","errorClass":"HTTPException","httpStatus":400,"severity":"error","filePath":"studio/backend/routes/models.py","lineNumber":2900,"sourceCode":"        deleted_count += 1\n    return deleted_count, deleted_bytes\n\n\n@router.delete(\"/delete-finetuned\")\nasync def delete_finetuned_model(\n    model_path: str = Body(...),\n    source: str = Body(...),\n    export_type: Optional[str] = Body(None),\n    gguf_variant: Optional[str] = Body(None),\n    current_subject: str = Depends(get_current_subject),\n):\n    \"\"\"Delete an Unsloth-trained or exported model from disk.\n\n    Only paths under Unsloth's outputs/exports roots are accepted.\n    Exported GGUF entries can delete one quant variant at a time.\n    \"\"\"\n    if source not in {\"training\", \"exported\"}:\n        raise HTTPException(\n            status_code = 400,\n            detail = \"Only trained or exported Unsloth models can be deleted\",\n        )\n\n    if not model_path or not model_path.strip():\n        raise HTTPException(status_code = 400, detail = \"model_path is required\")\n\n    if export_type == \"gguf\" and not gguf_variant:\n        raise HTTPException(\n            status_code = 400,\n            detail = \"gguf_variant is required when export_type is 'gguf'\",\n        )\n\n    raw_path = Path(model_path).expanduser()\n    if source == \"training\":\n        target_path = raw_path\n        allowed_root = outputs_root()\n    else:","sourceCodeStart":2882,"sourceCodeEnd":2918,"githubUrl":"https://github.com/unslothai/unsloth/blob/203007d19051dcd2ae33876786d117c99f6b0368/studio/backend/routes/models.py#L2882-L2918","documentation":"Raised as a 400 by the Unsloth model-delete endpoint when the request body's source field is not one of {'training', 'exported'}. The endpoint deliberately deletes only artifacts Unsloth itself created under its outputs/exports roots, so any other source value is refused before path validation begins.","triggerScenarios":"POST to the delete endpoint with body {\"model_path\": ..., \"source\": \"hub\"} (or 'custom', 'local', missing) — anything outside the two allowed literals.","commonSituations":"Front-end delete button wired to a generic model list that includes Hub/local entries; API consumers assuming the endpoint is a general model deleter; typos/casing ('Exported' vs 'exported').","solutions":["Send source='training' for Unsloth-trained checkpoints or source='exported' for exported artifacts (including per-variant GGUF deletes with export_type='gguf' and gguf_variant).","Do not use this endpoint for Hub-downloaded or arbitrary local models — remove those with your own file tooling.","Check casing: the comparison is exact against the lowercase literals."],"exampleFix":"# before\nclient.post('/api/models/unsloth/delete', json={'model_path': p, 'source': 'Exported'})  # 400\n\n# after\nclient.post('/api/models/unsloth/delete', json={'model_path': p, 'source': 'exported', 'export_type': 'gguf', 'gguf_variant': 'Q4_K_M'})","handlingStrategy":"type-guard","validationCode":"const DELETABLE_SOURCES = ['training', 'exported'] as const;\nif (!DELETABLE_SOURCES.includes(entry.source)) {\n  throw new Error(`cannot delete ${entry.source} models here — only Unsloth 'training'/'exported' artifacts`); \n}","typeGuard":"type UnslothSource = 'training' | 'exported';\nfunction isDeletableSource(s: unknown): s is UnslothSource {\n  return s === 'training' || s === 'exported';\n}","tryCatchPattern":"try {\n  await deleteModel({model_path, source});\n} catch (e) {\n  if (e.status === 400 && /Only trained or exported/.test(e.detail)) {\n    disableDeleteButton(); // entry is not an Unsloth artifact\n  } else throw e;\n}","preventionTips":["Only show the delete action for entries whose source is exactly 'training' or 'exported' (lowercase).","Do not reuse this endpoint for Hub or arbitrary local models — manage those separately.","For GGUF exports always send export_type='gguf' plus gguf_variant."],"tags":["models","unsloth","validation","api","delete"],"backgroundTag":null,"analyzedSha":"203007d19051dcd2ae33876786d117c99f6b0368","analyzedAt":"2026-08-15T02:48:39.846Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}