← Back to Pull requests

[Inference Providers] Route chat through the router and drop chat provider helpers #5333

Merged
hanouticelina merged 2 files (114 lines) on Nov 16, 2026 14:44 UTC
View on GitHub
hanouticelina hanouticelina commented on Nov 10, 2026 17:06 UTC
Author

With a HF token, chat_completion with a provider now goes through the router's /v1/chat/completions with model:provider. Provider keys still call the provider directly.

Why: the router only applies its server-side routing on /v1/chat/completions (auto, :cheapest/:fastest/:preferred policies, model:provider pins). Provider routes like /together/v1/chat/completions skip it and go straight to the provider. Today, the client calls those routes as soon as a provider is set, so these calls never get the router's routing. Sending model:provider to /v1/chat/completions gives them the same path as auto calls and the Hub snippets, and the client no longer needs the Hub mapping lookup for chat.

before: client -> Hub mapping lookup -> /together/v1/chat/completions -> Together
after:  client -> /v1/chat/completions (model:together) -> router routing -> Together

The inference guide now describes chat through the router and OpenRouter, uses a live model in the chat examples, and drops the provider/task table in favor of the Inference Providers docs. The code for the other providers is unchanged.

A cleanup PR will follow after the go-live, to avoid side effects.

Note: this PR was opened by an Agent (Opus 5.5) and reviewed by @hanouticelina

<!-- CURSOR_SUMMARY -->
---

[!NOTE]

Medium Risk

Changes default request paths for HF-token chat with a pinned provider, which could affect routing, billing, and provider selection; docs-only risk is low otherwise.

> Overview

Chat with a HF token and an explicit provider now goes through the Hugging Face router at /v1/chat/completions with model set to hf-model-id:provider, instead of calling provider-specific routes that skip router-side routing. Provider API keys are unchanged and still hit the provider directly.

> The inference guide is updated to match: chat examples use the router/OpenRouter flow and a live model, provider-specific chat samples are simplified, the large provider×task matrix is removed in favor of the Inference Providers docs, and related sections (function calling, structured outputs, MCP) align with default router usage.

> <sup>Reviewed by Cursor Bugbot for commit e34c9927784f9606b82d5dae1d361ed0d26cd2eb. Bugbot is set up for automated code reviews on this repo. Configure here.</sup>

<!-- /CURSOR_SUMMARY -->

Diff: 114 lines (+56 / -58) across 2 files Reviewer: Wauplin Review duration: 8497m
All Vouch review confidence checks passed
Residual risk 0.03 = Change Risk (0.33) × (1 − Review Confidence (0.91)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.33 · 114 lines diff across 2 files
0.33
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.89 · 2 substantive comment(s)
0.89
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
90%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.284
Real PR Conversation Timeline
6 items
bot-ci-comment[bot] bot-ci-comment[bot] commented on Nov 10, 2026 17:09 UTC
Bot

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Pages changed in this PR:

  • en/guides/inference
  • mangeshraut712 mangeshraut712 commented on Nov 10, 2026 17:39 UTC
    Reviewer

    This is a useful change: with an hf_ token, a provider-pinned chat call now goes through the router as model:provider and skips the Hub mapping lookup. A couple of residual cases worth tightening:

    1. Double :provider suffix. The new branch always builds f"{model}:{self.provider}". If the caller already passed a router id (meta-llama/Llama-3.3-70B-Instruct:together), this becomes ...:together:together. The same issue showed up on the JS sibling (huggingface.js#2843). Worth skipping the suffix when model already ends with :{provider}, and adding a test for that input.

    2. Empty model. The guard is only model is not None, so model="" still routes to the router as :together. Rejecting a missing/empty model (or falling through to super()) would be safer.

    3. Coverage. The new tests cover Together with an HF token vs a provider key, which is the core split. A case where model already has the suffix, and one for a second provider helper, would lock the routing rule down more clearly.

    The provider != "auto" check also avoids recursing into AutoRouterConversationalTask when that helper's provider is "auto", which is the right cut.

    hanouticelina hanouticelina commented on Nov 10, 2026 22:13 UTC
    Reviewer

    ✔️

    Wauplin Wauplin approved these changes on Nov 11, 2026 05:29 UTC
    Approved Reviewer

    Very clean!

    huggingface-hub-bot[bot] huggingface-hub-bot[bot] commented on Nov 26, 2026 15:43 UTC
    Bot

    This PR has been shipped as part of the v2.5.0 release.

    Reviewers
    Assignees
    hanouticelina hanouticelina
    Labels
    risk: low confidence: 90.6% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 32.8% (LOW) · Higher = larger blast radius
    32.8%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 90.6% · Lower = rushed or shallow review
    90.6%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 3.1% · Safe to merge
    3.1%