{"record":{"id":"f125848442618934","repo":"unslothai/unsloth","slug":"access-to-repo-is-gated-or-unauthorized-accep","errorCode":null,"errorMessage":"Access to '{repo}' is gated or unauthorized. Accept the model's license on its Hugging Face page and add your HF token in Studio settings, then try again.","messagePattern":"Access to '(.+?)' is gated or unauthorized\\. Accept the model's license on its Hugging Face page and add your HF token in Studio settings, then try again\\.","errorType":"http","errorClass":"HTTPException","httpStatus":400,"severity":"error","filePath":"studio/backend/routes/training.py","lineNumber":2623,"sourceCode":"    # clone counts: a directory named exactly like the vendor id is what the loaders and the\n    # mirror override both resolve on disk, and it carries one slash and no leading marker, so\n    # without the existence test this HEADs the gated repo and 400s a run that never leaves disk.\n    if (\n        not repo\n        or repo.count(\"/\") != 1\n        or repo.startswith((\".\", \"/\", \"~\"))\n        or repo.endswith(\".gguf\")\n        or _is_local_path(repo)\n    ):\n        return\n    url = f\"https://huggingface.co/{repo}/resolve/main/model_index.json\"\n    headers = {\"Authorization\": f\"Bearer {hf_token}\"} if hf_token else {}\n    req = urllib.request.Request(url, method = \"HEAD\", headers = headers)\n    try:\n        urllib.request.urlopen(req, timeout = 5)\n    except urllib.error.HTTPError as e:\n        if e.code in (401, 403):\n            raise HTTPException(\n                status_code = 400,\n                detail = (\n                    f\"Access to '{repo}' is gated or unauthorized. Accept the model's license \"\n                    f\"on its Hugging Face page and add your HF token in Studio settings, then \"\n                    f\"try again.\"\n                ),\n            )\n        # 404 (e.g. a repo without a root model_index.json) and other codes are not an access problem; let the trainer surface any genuine load error.\n    except Exception:  # noqa: BLE001 -- network/DNS hiccup must not block a start\n        return\n\n\ndef _resolve_diffusion_data_dir(raw: str) -> Path:\n    \"\"\"Resolve a diffusion-training ``data_dir``. The upload/labeling routes create and\n    manage image datasets directly under ``datasets_root()`` and the UI passes the bare\n    folder name back as ``data_dir``, but the generic :func:`resolve_dataset_path`\n    searches the LLM uploads and recipe dataset roots FIRST -- so an unrelated upload\n    file or recipe folder sharing that name would shadow the just-uploaded image","sourceCodeStart":2605,"sourceCodeEnd":2641,"githubUrl":"https://github.com/unslothai/unsloth/blob/203007d19051dcd2ae33876786d117c99f6b0368/studio/backend/routes/training.py#L2605-L2641","documentation":"HTTP 400 raised by the diffusion-model preflight: for a Hub repo (not local, not .gguf) the route sends a HEAD request to https://huggingface.co/{repo}/resolve/main/model_index.json with the caller's HF token. A 401/403 response means the repo is gated and the token has not accepted its license (or the token lacks access), so training would fail later anyway — the route fails fast with instructions. 404 and network errors are intentionally ignored (not an access problem).","triggerScenarios":"POST diffusion training start with model_repo_id pointing at a gated Hub repo (e.g. FLUX dev variants) while hf_token is missing, expired, or belongs to an account that has not accepted the model's license.","commonSituations":"New users copying a trendy gated model name without a token; tokens revoked/expired; accounts that accepted the license on one account but use another's token.","solutions":["Open the model's Hugging Face page and accept its license agreement.","Add/refresh a valid HF token with access to the repo in Studio settings.","Retry the training start; verify quickly with: curl -I -H \"Authorization: Bearer $HF_TOKEN\" https://huggingface.co/{repo}/resolve/main/model_index.json (expect 200/302, not 401/403)."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"async function canAccessRepo(repo, token) {\n  const res = await fetch(`https://huggingface.co/${repo}/resolve/main/model_index.json`, {\n    method: 'HEAD', headers: token ? {Authorization: `Bearer ${token}`} : {},\n  })\n  return res.status !== 401 && res.status !== 403 // 404 means: not an access problem\n}\nif (!(await canAccessRepo(modelRepo, hfToken))) throw new Error('Accept the model license on HF and set a valid token first')","typeGuard":null,"tryCatchPattern":"try { await startDiffusion(payload) } catch (e) { if (e.status === 400 && /gated or unauthorized/.test(e.detail)) { promptUser('Accept the license on the model page and add an HF token in Settings'); return } throw e }","preventionTips":["Pre-flight gated repos with an authenticated HEAD request before starting training.","Keep the Studio HF token fresh; verify it after any HF password/token rotation.","Accept gated-model licenses on the same HF account the token belongs to."],"tags":["huggingface","gated-model","auth","token","http-400"],"backgroundTag":null,"analyzedSha":"203007d19051dcd2ae33876786d117c99f6b0368","analyzedAt":"2026-08-15T02:48:39.846Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}