Problem/Motivation

Summary

Add a per-model "Inference provider" setting to the Huggingface provider so a configured model can be served by any Hugging Face Inference Provider
(hf-inference, Replicate, fal-ai, Together, …) instead of only hf-inference.
This issue delivers the framework + the default hf-inference adapter only — no behavior change for existing sites. Each partner provider is added in its own follow-up issue.

Problem

The Huggingface provider hardcodes the hf-inference serverless route
(router.huggingface.co/hf-inference/models/{model}) for every non-chat operation. As of mid-2025 hf-inference focuses on CPU models, so most current image/video generation models (FLUX.2, SVD, etc.) are served only by partner Inference Providers (Replicate, fal-ai, Together, …). Site builders currently cannot reach those models except by manually pasting a dedicated endpoint URL.
Each provider exposes the same task with the same request params but a different response protocol (raw bytes vs. base64 vs. fetch-output-URL vs. poll), so a single hardcoded path cannot serve them.

Proposed resolution

A HuggingfaceInferenceProvider plugin type: one adapter plugin per provider, each declaring the operation types it serves and encapsulating its request/response handling. A per-model select (built from the adapters that declare the operation) chooses the provider; hf-inference stays the default.
Chat is intentionally not an adapter task — Hugging Face's unified /v1/chat/completions router already routes chat to providers server-side.

Affected modules / components

ai_provider_huggingface (provider plugin, HuggingfaceApi client, model form).

Testing instructions

  1. Enable ai_provider_huggingface and configure a Hugging Face API key.
  2. Add a Text-to-image model — confirm it still works via hf-inference with no new required fields.
  3. drush php:eval the plugin manager: confirm hf-inference is discovered and declares its tasks.
  4. Run the unit tests: phpunit ai_provider_huggingface/tests/src/Unit/InferenceProvider/AdapterTest.php.

Remaining tasks

User interface changes

API changes

Data model changes

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

ahmad khader created an issue. See original summary.

ahmad khader’s picture

Status: Active » Needs review

This task will help us support text-to-video, text-to-speech, automatic-speech-recognition, text-generation (distinct from chat), image-segmentation, image-to-text, fill-mask, sentence-similarity, table-question-answering, tabular-classification, zero-shot-classification, zero-shot-image-classification, document-question-answering, audio-classification, audio-to-audio, visual-question-answering, image-to-video, text-to-image, and image-to-image operation types in the future.

ahmad khader changed the visibility of the branch 3601100-base---configurable to hidden.

ahmad khader changed the visibility of the branch 3601100-base---configurable to active.