| name | hugging-face-api |
| description | Expert knowledge for Hugging Face REST APIs — the Hub API (model search and downloads), the Inference API (serverless model execution), and programmatic access from Python/Rust. Use when searching or downloading models, calling hosted inference, or integrating Hugging Face into Rust or Python tooling. |
Hugging Face REST API
Comprehensive expertise for interacting with Hugging Face's API ecosystem, including model discovery, programmatic downloads, inference operations, and GGUF model management.
Core APIs
| API | Purpose | Use Case |
|---|
| Hub API | Model/dataset metadata, search, repository management | Discovering and managing models |
| Inference API | Serverless model inference | Quick prototyping, light production |
| Inference Endpoints | Dedicated infrastructure | Production workloads |
| Inference Providers | Unified third-party access | Cross-provider compatibility |
Quick Reference
Authentication Setup
from huggingface_hub import HfApi, InferenceClient
api = HfApi(token="hf_...")
client = InferenceClient(token="hf_...")
Model Search
from huggingface_hub import ModelFilter
filter = ModelFilter(
task="text-generation",
library="pytorch",
language="english"
)
models = api.list_models(filter=filter, limit=10)
Run Inference
result = client.text_generation(
"The future of AI is",
model="gpt2",
max_new_tokens=50
)
results = client.image_classification(
image,
model="google/vit-base-patch16-224"
)
Key Principles
- Use client libraries when available (Python/JavaScript) for simplified interactions
- Implement proper authentication with fine-grained tokens for production
- Handle rate limits gracefully with exponential backoff
- Cache model downloads to avoid redundant transfers
- Choose the right inference tier - serverless for prototypes, endpoints for production
Detailed Topics
Setup & Configuration
Model Operations
Inference
Specialized Formats
- GGUF Models - Finding, listing, and downloading quantized models (with Rust examples)
API Limits & Pricing
| Tier | Rate Limits | Monthly Cost | Use Case |
|---|
| Free | ~Few hundred/hour | $0 | Development, testing |
| Pro | 20x higher | $9 | Light production |
| Enterprise | Custom | Custom | Scale production |
Resources