> ## Documentation Index
> Fetch the complete documentation index at: https://docs.coreflux.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Hugging Face Hub

> Client-mode REST API connectors for Hugging Face: triage alarms with OpenAI-compatible chat completions through Inference Providers, create embeddings and classify camera snapshots with HF Inference, pause, resume or scale dedicated Inference Endpoints to zero to control cost, call your own anomaly model, and search Hub models, all with a Hugging Face token

Technical Preview

## Overview

Client-mode REST API connectors for Hugging Face: triage alarms with OpenAI-compatible chat completions through Inference Providers, create embeddings and classify camera snapshots with HF Inference, pause, resume or scale dedicated Inference Endpoints to zero to control cost, call your own anomaly model, and search Hub models, all with a Hugging Face token.

This is one of the templates in the Hugging Face Inference Providers and Endpoints REST API app (`hugging-face-inference-providers-and-endpoints`). Deploy it alongside the other connectors of that app when they depend on each other (for example a token connector plus an API connector).

> [!NOTE]
>
> Not yet verified against the live vendor API: No Hugging Face token on the factory box. Needs a Hugging Face account with a fine-grained user access token (HF\_TOKEN) with 'Make calls to Inference Providers' (plus credits: free monthly \$0.10 or PRO/Team) for ChatCompletion / FeatureExtraction / ImageClassification, and Inference Endpoints read/write + a namespace (user or org with a payment method) for ListEndpoints / GetEndpoint / Pause / Resume / ScaleToZero, ideally one small CPU test endpoint (e.g. aws eu-west-1 intel-spr x1, scale-to-zero) for the dedicated connector. Then run HF\_TOKEN=... \[HF\_NAMESPACE=...] python3 smoke\_huggingface.py: WhoAmI GET + ListRouterModels GET + ChatCompletion POST + FeatureExtraction POST (+ ListEndpoints GET) must return 200. Public Hub/router GETs returning 200 without a token do not clear the gate.

## Auth

Hugging Face user access token as Authorization: Bearer \{value.json.hf\_token} on every event. Fine-grained token: 'Make calls to Inference Providers' (router chat / task events) + Inference Endpoints read/write (management + dedicated endpoint calls). Hub secret suggested HF\_TOKEN + GET SECRET. Public router / Hub GETs answer without a valid token. Never commit tokens.

Auth headers used by the template: `Authorization: Bearer {value.json.hf_token}`.

## Template parameters

| Placeholder | Type | Description | Required |
| - | - | - | - |
| `RouteName` | string | Name of the Hugging Face Hub connector | no |
| `BaseUrl` | string | Hugging Face Hub base URL without trailing slash (e.g. [https://huggingface.co](https://huggingface.co)) | yes |

`BASE_ADDRESS` default: `https://huggingface.co`.

## Events

| Event | Method | Endpoint | Request topic | Response topic | Payload fields |
| - | - | - | - | - | - |
| `WhoAmI` | GET | `/api/whoami-v2` | `ai/huggingface/account/whoami` | `ai/huggingface/account/whoami/response` | `hf_token` |
| `SearchModels` | GET | `/api/models?search={value.json.search}&pipeline_tag={value.json.pipeline_tag}&sort={value.json.sort}&limit={value.json.limit}` | `ai/huggingface/hub-model/search` | `ai/huggingface/hub-model/search/response` | `hf_token`, `limit`, `pipeline_tag`, `search`, `sort` |
| `GetModelInfo` | GET | `/api/models/{value.json.model_id}` | `ai/huggingface/hub-model/get` | `ai/huggingface/hub-model/get/response` | `hf_token`, `model_id` |

## Deploy

Get the template card (JSON with `template` and `metadata`) from the broker, then deploy the connector:

```bash theme={"theme":"css-variables","languages":{"custom":["/languages/lot.json"]}}
mosquitto_pub -t '$SYS/Coreflux/Command' -m "-routeCode HUGGING_FACE_HUB"
```

The deployable connector from the REST API app, with `BASE_ADDRESS` already filled in:

```lot theme={"theme":"css-variables","languages":{"custom":["/languages/lot.json"]}}
DEFINE ROUTE HuggingFaceHub WITH TYPE REST_API
    ADD REST_API_CONFIG
        WITH BASE_ADDRESS "https://huggingface.co"
        WITH ENABLE_CLIENT "true"
        WITH USE_SSL "true"
        WITH REQUEST_TIMEOUT '30'
        WITH DEFAULT_CONTENT_TYPE "application/json"
    ADD EVENT WhoAmI
        WITH SOURCE_TOPIC "ai/huggingface/account/whoami"
        WITH DESTINATION_TOPIC "ai/huggingface/account/whoami/response"
        WITH METHOD "GET"
        WITH ENDPOINT "/api/whoami-v2"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Authorization" "Bearer {value.json.hf_token}"
    ADD EVENT SearchModels
        WITH SOURCE_TOPIC "ai/huggingface/hub-model/search"
        WITH DESTINATION_TOPIC "ai/huggingface/hub-model/search/response"
        WITH METHOD "GET"
        WITH ENDPOINT "/api/models?search={value.json.search}&pipeline_tag={value.json.pipeline_tag}&sort={value.json.sort}&limit={value.json.limit}"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Authorization" "Bearer {value.json.hf_token}"
    ADD EVENT GetModelInfo
        WITH SOURCE_TOPIC "ai/huggingface/hub-model/get"
        WITH DESTINATION_TOPIC "ai/huggingface/hub-model/get/response"
        WITH METHOD "GET"
        WITH ENDPOINT "/api/models/{value.json.model_id}"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Authorization" "Bearer {value.json.hf_token}"
```

Deploy it with `-addRoute` (do not include `ADD METADATA`).

## Usage example

Call `WhoAmI` by publishing a JSON payload to its request topic, and read the reply on the response topic:

```bash theme={"theme":"css-variables","languages":{"custom":["/languages/lot.json"]}}
mosquitto_sub -t 'ai/huggingface/account/whoami/response' &
mosquitto_pub -t 'ai/huggingface/account/whoami' -m '{"hf_token": "<hf_token>"}'
```

## Related

* [REST API Connectors](/latest/lot-language/routes/rest-api-routes)
* [REST API Apps catalog](/latest/lot-language/routes/rest-api-apps)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.