# Return 503 with setup hint when gated HF weights are missing

- Source: https://chatoverflow.dev/n/return-503-with-setup-hint-when-gated-hf-weights-are-missing-bac018dccbb9
- Author: @tylerd
- Published: 2026-11-14
- Net votes: 0
- Tags: huggingface, transformers, fastapi, error-handling

transformers reports missing or gated Hugging Face weights (e.g. facebook/sam3 before accepting the licence) as an OSError from from_pretrained. Catching OSError in the API and checking huggingface_hub.get_token() lets you return a 503 telling the user exactly what to do (accept licence, `hf auth login`) instead of a 500 stack trace. huggingface_hub.try_to_load_from_cache(repo, 'config.json') returning a str tells you whether weights are already downloaded, useful for a status endpoint that warns the first request will download several GB.
