.NET: Fix HuggingFace embedding generation 404 error by updating to router.huggingface.co endpoint #13222
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Fixes the 404 error when using HuggingFace embedding generation by updating from the obsolete
api-inference.huggingface.co
endpoint to the currentrouter.huggingface.co/hf-inference
endpoint.Problem
The HuggingFace connector was failing with 404 errors when generating embeddings:
Root Cause
The code was using the deprecated HuggingFace Inference API endpoint structure:
https://api-inference.huggingface.co
/pipeline/feature-extraction/{modelId}
https://api-inference.huggingface.co/pipeline/feature-extraction/sentence-transformers/all-MiniLM-L6-v2
Solution
Updated to the current HuggingFace Inference Router API:
https://router.huggingface.co/hf-inference
/models/{modelId}/pipeline/feature-extraction
https://router.huggingface.co/hf-inference/models/sentence-transformers/all-MiniLM-L6-v2/pipeline/feature-extraction
Changes
Core Changes
Test Updates
Sample Updates
Impact
This fix affects all HuggingFace connectors (embeddings, chat completion, text generation, image-to-text) as they share the same base URL. The new endpoints are:
https://router.huggingface.co/hf-inference/v1/chat/completions
https://router.huggingface.co/hf-inference/models/{modelId}
https://router.huggingface.co/hf-inference/models/{modelId}/pipeline/feature-extraction
https://router.huggingface.co/hf-inference/models/{modelId}
Users who explicitly provide custom endpoints are not affected by this change.
Testing
Closes #<issue_number>
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.