Skip to content

feat(huggingface-extras): add Inference Providers plugin for image, embeddings, STT, video - #63487

Closed
lyfuci wants to merge 5 commits into
openclaw:mainfrom
lyfuci:feat/huggingface-extras-image-gen
Closed

lyfuci wants to merge 5 commits into
openclaw:mainfrom
lyfuci:feat/huggingface-extras-image-gen

Conversation

@lyfuci

@lyfuci lyfuci commented Apr 9, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds a new bundled plugin extensions/huggingface-extras/ that wires four contracts onto a single huggingface-extras provider id:

Contract Provider route Default model
Image generation router/hf-inference/models/<id> black-forest-labs/FLUX.1-schnell
Memory embeddings router/scaleway/v1/embeddings qwen3-embedding-8b
Audio transcription (STT) router/hf-inference/models/<id> openai/whisper-large-v3
Video generation router/replicate/v1/models/<providerId>/predictions Wan-AI/Wan2.1-T2V-14B

All four share one HF token (`HUGGINGFACE_HUB_TOKEN` / `HF_TOKEN`) and one onboarding choice. The plugin is `enabledByDefault: false`.

Why this is useful

Hugging Face hosts an enormous catalog of community models, and the Inference Providers router exposes a lot of them through one consistent HTTP surface. Today an openclaw user who wants image generation, embeddings, or STT has to configure a separate provider account (fal-ai, voyage, ElevenLabs, etc.) for each capability. With this plugin, a single HF token unlocks all four task types and the user can experiment with hundreds of models by just changing a model id in `openclaw.json`.

The HF Pro $2 / month free tier covers all four routes used here, so the plugin is also a low-friction way to get started without spinning up a local Ollama or paying multiple vendors.

Open question for reviewers

Would you prefer this to be merged into the existing `extensions/huggingface/` plugin instead, exposing all four contracts under the single `huggingface` provider id?

We took the view that these contracts deserve their own plugin so:

  • chat behavior (currently the entire scope of `extensions/huggingface/`) is not perturbed if a non-chat helper changes
  • users can disable extras independently
  • the new code lives in one folder and reviewers don't need to chase diffs across the existing huggingface plugin

But if the maintainers prefer a single `huggingface` provider id covering everything, happy to refactor — the current split is just what we found cleanest, not a strong opinion. Related issue: #11353.

Implementation notes

  • Image: `hf-inference/models/` POST with JSON body, raw PNG bytes back. The legacy `api-inference.huggingface.co` host was retired in 2026, so we point at `router.huggingface.co/hf-inference` instead.
  • Embeddings: Scaleway is the only HF Inference Providers backend that hosts `Qwen/Qwen3-Embedding-8B` (4096-dim multilingual). Uses the OpenAI-compatible `/v1/embeddings` shape.
  • STT: HF router does not expose `/v1/audio/transcriptions`, so we POST raw audio bytes to `hf-inference/models/openai/whisper-large-v3`. Cannot reuse `transcribeOpenAiCompatibleAudio()` because the URL shape differs.
  • Video: Replicate is the only non-fal-ai HF Pro route serving the Wan family. fal-ai requires pre-paid credits outside the HF Pro tier so we intentionally skip it. Unknown model ids are resolved at runtime via `https://huggingface.co/api/models/{id}?expand[]=inferenceProviderMapping\`, cached in-memory, with a bundled fallback for the four supported Wan models. Models that only route through fal-ai (HunyuanVideo, mochi-1, CogVideoX, LongCat, LTX-Video) trigger an explicit warning that lists the supported alternatives.

Test plan

  • `pnpm tsgo --project extensions/huggingface-extras/tsconfig.json`
  • `pnpm lint`
  • `pnpm format`
  • Plugin loads on a live gateway (`huggingface-extras: loaded` in `[plugins]` log, 4 contracts registered)
  • Image gen verified end-to-end: FLUX.1-schnell returned a 1024x1024 PNG
  • Embeddings verified end-to-end: switched `memorySearch.provider` to `huggingface-extras`, full reindex of 52 files / 243 chunks via Scaleway succeeds, semantic search returns relevant matches
  • STT verified at the router level (`{"text": "..."}` from whisper-large-v3)
  • Video gen verified end-to-end: Wan-AI/Wan2.1-T2V-14B returned a 246 KB MP4 via replicate

Known limitations / future work

  • No unit tests yet — will add as a follow-up if the architecture is accepted, since the test shape depends on whether this stays as `huggingface-extras` or merges into `huggingface`.
  • No docs page under `docs/providers/`.
  • Wavespeed, Together, Nscale routes for video are not implemented — only Replicate (covers the four supported Wan models).
  • TTS / realtime voice / music generation are not on the HF Inference Providers task matrix today, so they are out of scope.
  • Image-to-image and image-to-video edits not implemented.

lyfuci added 5 commits April 8, 2026 19:07
New bundled plugin extensions/huggingface-extras/ that registers an image
generation provider against the Hugging Face Inference API. Phase 1 only:
text-to-image via /models/<id>, default model FLUX.1-schnell, supports size,
aspectRatio, and resolution. Phases 2 and 3 will add embeddings and speech
contracts against the same provider id.

Complements the chat-only huggingface plugin which routes through the HF
Inference Providers OpenAI-compatible router.
Fix tsgo errors:
- resolveApiKeyForProvider param is named 'store' not 'authStore'
- the function returns ResolvedProviderAuth, extract .apiKey

Apply oxfmt formatting.
The legacy api-inference.huggingface.co host was retired in favor of the
Inference Providers router. The hf-inference route at
https://router.huggingface.co/hf-inference/models/<id> is the closest
drop-in replacement and stays free for HF Pro users; the request body
shape (inputs + parameters) and the raw image binary response are
unchanged, so only the base URL needs to move.

Verified locally with FLUX.1-schnell returning a 1024x1024 image.
Adds two more contracts to the huggingface-extras plugin so HF Pro users
get a single provider id covering image generation, memory embeddings, and
audio transcription:

- embeddings-provider.ts: MemoryEmbeddingProviderAdapter routing through
  Scaleway's OpenAI-compatible /v1/embeddings endpoint with default model
  qwen3-embedding-8b. Supports batch and query, returns 4096-dim vectors.
- stt-provider.ts: MediaUnderstandingProvider whose transcribeAudio() POSTs
  raw audio bytes to the hf-inference whisper-large-v3 model. We cannot
  reuse transcribeOpenAiCompatibleAudio() because the HF router does not
  expose /v1/audio/transcriptions on this route.
- index.ts: register both new contracts alongside the existing image gen
  provider; same auth profile.
- openclaw.plugin.json: declare memoryEmbeddingProviders and
  mediaUnderstandingProviders contracts.
- api.ts: re-export the new SDK types and add the Scaleway base URL.

Verified locally:
- Plugin loads without error after restart.
- memorySearch.provider switched to huggingface-extras, full reindex of
  52 files / 243 chunks via Scaleway succeeds, search returns matches.
- whisper-large-v3 endpoint returns 200 + {text:...} (probed via curl).
Adds the fourth contract to huggingface-extras: text-to-video routed through
the HF Inference Providers replicate backend. fal-ai is intentionally not
used because it requires pre-paid credits outside the HF Pro $2 monthly tier.

Implementation:
- video-generation-provider.ts builds a VideoGenerationProvider whose
  generateVideo() resolves the HF model id to a replicate providerId via a
  bundled mapping (Wan family) plus a runtime fallback that calls the public
  HF Hub /api/models/{id}?expand[]=inferenceProviderMapping endpoint.
- POSTs to https://router.huggingface.co/replicate/v1/models/{providerId}/predictions
  and polls /v1/predictions/{id} every 3s until status=succeeded, then
  downloads the output URL as raw mp4 bytes.
- For models without a live replicate route (HunyuanVideo, mochi-1-preview,
  CogVideoX, LongCat, LTX-Video and similar fal-ai-only entries), the
  resolver throws a clear warning that lists the four supported Wan models
  the user can actually run today and explains that fal-ai requires
  pre-paid credits.
- Mapping cache is module-level (cleared on restart) to mirror the upstream
  HF JS SDK behavior.

Default model: Wan-AI/Wan2.1-T2V-14B. Other live models in the bundled
mapping: Wan2.1-T2V-1.3B, Wan2.2-T2V-A14B, Wan2.2-TI2V-5B.
@steipete

Copy link
Copy Markdown
Contributor

Thanks @lyfuci. I’m going to close this draft rather than try to land it in its current form.

Main blockers:

  • Provider configuredness is wrong: image isConfigured always returns true at extensions/huggingface-extras/image-generation-provider.ts:218, and video does the same at extensions/huggingface-extras/video-generation-provider.ts:295. That would make media tools appear/auto-select without an HF token, then fail at request time.
  • The HTTP path bypasses the shared provider transport/SSRF policy. Image uses raw fetch at extensions/huggingface-extras/image-generation-provider.ts:168, and video downloads a provider-returned URL with raw fetch at extensions/huggingface-extras/video-generation-provider.ts:233. Provider code needs the SDK HTTP helpers / guarded fetch path so proxy/TLS/dispatcher/timeout and private-network policy stay consistent.
  • Architecture is unresolved: this creates a second provider id, huggingface-extras, with the same token/env vars and /providers/huggingface docs path, while extensions/huggingface already owns the Hugging Face provider. The PR body calls this out too. If we add these capabilities, I’d want a smaller design first: either extend huggingface, or explicitly document/justify a separate provider id.
  • It has no tests or docs yet. pnpm test:changed found no huggingface-extras tests. New media/provider surfaces also need docs, changelog, labeler/GitHub label if a new plugin id is accepted.
  • The related issue [Feature]: Add huggingface inference providers support #11353 is already closed as completed.

Suggested path: reopen as one smaller PR for one capability, probably against the existing huggingface plugin, with auth-aware configuredness, SDK guarded HTTP helpers, focused tests, docs/changelog. Video can follow after the async/download path is covered.

I did not treat the branch build failure as a primary blocker because the branch is old and CI is skipped while draft; the items above are enough to block landing independently.

@steipete steipete closed this Apr 25, 2026
@lyfuci
lyfuci deleted the feat/huggingface-extras-image-gen branch April 26, 2026 04:52
@lyfuci

lyfuci commented Apr 26, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by #72129 — much smaller scope (text-to-image only, bundled into the existing huggingface plugin), addressing all five items from your earlier review.

lyfuci added a commit to lyfuci/openclaw that referenced this pull request Jun 23, 2026
Adds image generation to the existing huggingface plugin (instead of
introducing a second plugin id), wired through the SDK's guarded
provider HTTP helpers so SSRF/proxy/timeout/dispatcher policy stays
consistent with the rest of the provider transport layer.

isConfigured now resolves the real auth state via
isProviderApiKeyConfigured rather than always reporting configured.

Out of scope for this change: image-to-image, edit, batches, video,
embeddings, STT, and Inference Providers routes other than
hf-inference. Those can each follow as their own focused PR.

Refs openclaw#63487
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants