> ## 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

> LoT connector for the Hugging Face Hub API: check the token account with WhoAmI, search models by task or name and get model info from MQTT topics

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).

## 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":{"light":"css-variables","dark":"css-variables"},"languages":{"custom":["/languages/lot.json"]}}
mosquitto_pub -t '$SYS/Coreflux/Command' -m "-connectorCode HUGGING_FACE_HUB"
```

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

```lot theme={"theme":{"light":"css-variables","dark":"css-variables"},"languages":{"custom":["/languages/lot.json"]}}
DEFINE CONNECTOR 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 `-addConnector` (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":{"light":"css-variables","dark":"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](https://docs.coreflux.org/latest/connectors/rest-api/overview)
* [REST API Apps catalog](https://docs.coreflux.org/latest/connectors/rest-api-apps)


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