[Inference Providers] Route chat through the router and drop chat provider helpers #5333
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/inferenceThis 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.
✔️
Very clean!
This PR has been shipped as part of the v2.5.0 release.
Wauplin
hanouticelina
With a HF token,
chat_completionwith aprovidernow goes through the router's/v1/chat/completionswithmodel:provider. Provider keys still call the provider directly.Why: the router only applies its server-side routing on
/v1/chat/completions(auto,:cheapest/:fastest/:preferredpolicies,model:providerpins). Provider routes like/together/v1/chat/completionsskip it and go straight to the provider. Today, the client calls those routes as soon as aprovideris set, so these calls never get the router's routing. Sendingmodel:providerto/v1/chat/completionsgives them the same path asautocalls and the Hub snippets, and the client no longer needs the Hub mapping lookup for chat.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 -->
---
<!-- /CURSOR_SUMMARY -->