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
- Enable
ai_provider_huggingfaceand configure a Hugging Face API key. - Add a Text-to-image model — confirm it still works via hf-inference with no new required fields.
drush php:evalthe plugin manager: confirmhf-inferenceis discovered and declares its tasks.- Run the unit tests:
phpunit ai_provider_huggingface/tests/src/Unit/InferenceProvider/AdapterTest.php.
Remaining tasks
User interface changes
API changes
Data model changes
Issue fork ai_provider_huggingface-3601100
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
Comment #3
ahmad khader commentedThis 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-imageoperation types in the future.