This source did not publish a separate summary. Review SKILL.md before using the skill.
SKILL.md
Hugging Face Hub API
Overview
The Hugging Face Hub is the largest open-source ML ecosystem, hosting over 1 million models, 200,000+ datasets, and 400,000+ Spaces (demo apps). The Hub API at https://huggingface.co/api provides programmatic access to search, discover, and retrieve metadata for all public resources without authentication.
For academic researchers, the Hub API enables systematic model selection for benchmarking, dataset discovery for experiments, tracking community adoption metrics (downloads, likes), and building reproducible ML pipelines that reference specific model revisions by SHA.
Authentication
Read endpoints require no authentication. All search and metadata queries work without a token.
For write operations (uploading models, creating repos), set a User Access Token:
Returns cardData with structured metadata (task categories, languages, license, size), description, paperswithcode_id for cross-referencing, and tags with arXiv paper IDs.
Search Spaces
GET https://huggingface.co/api/spaces?search={query}&limit={n}
Combine filters via query params to narrow results:
# PyTorch text-generation models with 1000+ likes
curl -s "https://huggingface.co/api/models?filter=text-generation&library=pytorch&sort=likes&direction=-1&limit=5"
# Datasets for NER tasks in Chinese
curl -s "https://huggingface.co/api/datasets?filter=token-classification&language=zh&limit=10"
# Gradio Spaces sorted by trending
curl -s "https://huggingface.co/api/spaces?filter=gradio&sort=trending&direction=-1&limit=5"
Rate Limits
Unauthenticated: generous but undocumented; suitable for interactive use and small scripts
Authenticated: higher limits with Bearer token
Best practice: add limit parameter to avoid fetching thousands of results; cache responses locally for batch analysis
No strict per-minute quota is published; if you receive HTTP 429, back off exponentially
Academic Use Cases
Model selection for benchmarks: Search by pipeline tag (text-classification, token-classification, summarization) and sort by downloads to find community-validated baselines
Dataset discovery: Filter by task_categories, language, and size_categories tags to find training data matching your experimental requirements
Reproducibility: Pin model versions using the sha field from model details -- load exact revisions with revision="86b5e093..." in transformers
Citation tracking: Extract arxiv: tags from model/dataset metadata to trace foundational papers
Ecosystem analysis: Aggregate download/like counts across model families to study adoption trends in ML research
Code Examples
Python with requests
import requests
# Search for top text-classification models
resp = requests.get("https://huggingface.co/api/models", params={
"filter": "text-classification",
"sort": "downloads",
"direction": -1,
"limit": 10
})
models = resp.json()
for m in models:
print(f"{m['id']:50s} downloads={m.get('downloads',0):>12,}")
# Get specific model metadata
detail = requests.get("https://huggingface.co/api/models/google-bert/bert-base-uncased").json()
print(f"SHA: {detail['sha']}")
print(f"License: {detail['cardData'].get('license')}")
Python with huggingface_hub library
from huggingface_hub import HfApi
api = HfApi()
# Search models (returns ModelInfo objects)
models = api.list_models(search="bert", sort="downloads", direction=-1, limit=5)
for m in models:
print(f"{m.id} downloads={m.downloads}")
# Get full model info
info = api.model_info("google-bert/bert-base-uncased")
print(f"Pipeline: {info.pipeline_tag}, SHA: {info.sha}")
# Search datasets
datasets = api.list_datasets(search="squad", sort="downloads", direction=-1, limit=5)
for d in datasets:
print(f"{d.id} downloads={d.downloads}")
# List Spaces
spaces = api.list_spaces(search="chatbot", limit=5)
for s in spaces:
print(f"{s.id} sdk={s.sdk}")