step
huggingface_inference
Run inference on Hugging Face models using the official huggingface_hub library.
Overview
This step provides access to thousands of pre-trained models hosted on Hugging Face for tasks
like text classification, named entity recognition, summarization, translation, question answering,
text generation, and more. It uses the official huggingface_hub library which automatically handles
API endpoint routing and authentication.
Setup:
1. Create a Hugging Face account at https://huggingface.co/
2. Generate an access token at https://huggingface.co/settings/tokens
3. Choose a model from https://huggingface.co/models (filter by task)
4. Store your token securely as an environment variable
API Token: Required. Get from https://huggingface.co/settings/tokens
like text classification, named entity recognition, summarization, translation, question answering,
text generation, and more. It uses the official huggingface_hub library which automatically handles
API endpoint routing and authentication.
Setup:
1. Create a Hugging Face account at https://huggingface.co/
2. Generate an access token at https://huggingface.co/settings/tokens
3. Choose a model from https://huggingface.co/models (filter by task)
4. Store your token securely as an environment variable
API Token: Required. Get from https://huggingface.co/settings/tokens
Examples
Sentiment analysis (auto-detected task)
Classify text sentiment - task is automatically detected from model metadata
type: huggingface_inference
model: distilbert/distilbert-base-uncased-finetuned-sst-2-english
api_token: ${env:HUGGINGFACE_TOKEN}
input_from: review.text
output_to: review.sentiment
Sentiment analysis (explicit task)
Classify text sentiment using DistilBERT with explicit task specification
type: huggingface_inference
model: distilbert/distilbert-base-uncased-finetuned-sst-2-english
api_token: ${env:HUGGINGFACE_TOKEN}
task: text-classification
input_from: review.text
output_to: review.sentiment
Text summarization
Generate concise summaries of long documents
type: huggingface_inference
model: facebook/bart-large-cnn
api_token: ${env:HUGGINGFACE_TOKEN}
task: summarization
input_from: article.full_text
output_to: article.summary
parameters:
max_length: 150
min_length: 50
timeout: 60
Named entity recognition
Extract people, organizations, and locations from text
type: huggingface_inference
model: dslim/bert-base-NER
api_token: ${env:HUGGINGFACE_TOKEN}
task: token-classification
input_from: document.content
output_to: document.entities
Question answering
Answer questions based on provided context
type: huggingface_inference
model: deepset/roberta-base-squad2
api_token: ${env:HUGGINGFACE_TOKEN}
task: question-answering
input_from: qa_input
output_to: answer
Text generation
Generate text continuations using GPT-2
type: huggingface_inference
model: openai-community/gpt2
api_token: ${env:HUGGINGFACE_TOKEN}
task: text-generation
input_from: prompt
output_to: generated
parameters:
max_new_tokens: 100
temperature: 0.7
Zero-shot classification
Classify text into custom categories without training
type: huggingface_inference
model: facebook/bart-large-mnli
api_token: ${env:HUGGINGFACE_TOKEN}
task: zero-shot-classification
input_from: text
output_to: classification
parameters:
candidate_labels:
- urgent
- not urgent
- spam
Configuration
| Parameter | Type | Required | Description |
|---|---|---|---|
model | string | Yes | Model id from the Hugging Face Hub with namespace (e.g., 'distilbert/distilbert-base-uncased-finetuned-sst-2-english'). |
api_token | string | Yes | Hugging Face API token. Get one at https://huggingface.co/settings/tokens |
task | string | No | The inference task to run. If omitted, automatically detected from the model metadata. Common tasks: text-classification, summarization, text-generation, question-answering, token-classification. |
input_from | string | No | Dot path to extract the input text from the event. When omitted, uses the entire event. |
input_key | string | No | DEPRECATED: Use 'input_from' instead. |
output_to | string | No | Event key where the inference result is stored.
Default: "huggingface" |
output_key | string | No | DEPRECATED: Use 'output_to' instead. |
parameters | string | No | Model-specific parameters (e.g., max_length, temperature, top_p). Passed directly to the model. |
task_params | string | No | DEPRECATED: Use 'parameters' instead. |
swallow_on_error | boolean | No | If True, return original event unchanged on errors instead of injecting error details.
Default: false |
timeout | integer | No | Request timeout in seconds (default 30).
Default: 30 |
provider | string | No | The inference provider to use. Default is 'hf-inference' (HuggingFace's native inference).
Default: "hf-inference" |
Base Configuration
These configuration options are available on all steps:
| Parameter | Type | Default | Description |
|---|---|---|---|
name | | null | Optional name for this step (for documentation and debugging) |
description | | null | Optional description of what this step does |
retries | integer | 0 | Number of retry attempts (0-10) |
backoff_seconds | number | 0 | Backoff (seconds) applied between retry attempts |
retry_propagate | boolean | false | If True, raise last exception after exhausting retries; otherwise swallow. |