404 Not Found when using https://router.huggingface.co/hf-inference
Author: oliveiradany07
Pull request: no
Labels: name: bug

### System Info

Hello Hugging Face Team,

I’m trying to use the new Router API endpoint for model inference:

https://router.huggingface.co/hf-inference

However, whenever I make a request, I always get a "Not Found" (404) response.

Here’s what I’m doing:

- API endpoint: https://router.huggingface.co/hf-inference/models/gpt2
- HTTP method: POST
- Headers: 
    Authorization: Bearer <MY_HF_API_KEY>
    Content-Type: application/json
- Body:
{
    "inputs": "Generate a complete HTML website for a candy shop. Return only HTML, CSS, JS."
}

Expected behavior:  
- The API should return generated text from the model (like it did with the old api-inference endpoint).

Actual behavior:  
- Always returns 404 Not Found.

I’ve tried with multiple public models (like `gpt2`, `EleutherAI/gpt-neo-125M`), but the problem persists.

Environment:  
- Node.js 20  
- Axios for HTTP requests  
- Hugging Face API key: valid and works with the old api-inference endpoint (deprecated)

Could you please advise if this is a bug or if there’s a change in how the Router API should be called?  

Thank you!


### Who can help?

_No response_

### Information

- [x] The official example scripts
- [x] My own modified scripts

### Tasks

- [ ] An officially supported task in the `examples` folder (such as GLUE/SQuAD, ...)
- [x] My own task or dataset (give details below)

### Reproduction

The tasks I am working on are:
- My own custom task: generating full HTML/CSS/JS websites from prompts.


### Expected behavior

The API should return generated text from the model (HTML, CSS, JS) based on the prompt.

Comments:
I think the problem is that you're including the model name in the address rather than the headers, right? Take a look at the example [here](https://huggingface.co/docs/inference-providers/en/index#http--curl)

I don't understand what you mean by that. Sorry. Here is my code btw : 

const express = require('express');
const axios = require('axios');
const router = express.Router();

const HF_API_KEY = process.env.HUGGINGFACE_API_KEY;

// Test route
router.get('/', (req, res) => {
  res.json({ message: 'AI Backend is running!' });
});

// Website generation route
router.post('/generate-website', async (req, res) => {
  const { prompt } = req.body;
  if (!prompt) return res.status(400).json({ error: "Prompt is required" });

  try {
    console.log('Generating website for:', prompt);

    // Hugging Face Router API endpoint
    const response = await axios.post(
      'https://router.huggingface.co/hf-inference', // Router API
      { inputs: `Create a complete HTML website for: ${prompt}. Return only HTML, CSS, JS.` },
      {
        headers: {
          Authorization: `Bearer ${HF_API_KEY}`,
          'Content-Type': 'application/json'
        },
        timeout: 60000 // 60s timeout
      }
    );

    let generatedHtml = response.data?.[0]?.generated_text || '';

    // Clean up markdown-style code blocks
    generatedHtml = generatedHtml.replace(/```html/g, '').replace(/```/g, '').trim();

    res.json({ success: true, html: generatedHtml });

  } catch (err) {
    console.error('AI Generation Error:', err.response?.data || err.message);
    res.status(500).json({ error: 'AI generation failed' });
  }
});

module.exports = router;


The models you used are no longer part of the [inference providers](https://huggingface.co/models?inference_provider=groq,novita,nebius,cerebras,sambanova,nscale,fal-ai,hyperbolic,together,fireworks-ai,featherless-ai,zai-org,replicate,cohere,scaleway,publicai,wavespeed,hf-inference&sort=trending) currently supported. 

For models such as `facebook/bart-large-cnn`, you can make POST requests to https://router.huggingface.co/hf-inference/models/facebook/bart-large-cnn. Including the model name in the URL will not necessarily result in a 404 error.

You can refer to the [doc](https://huggingface.co/docs/inference-providers/tasks/text-generation) for details on text generation using models like `gpt-oss-120b`.

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the [contributing guidelines](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md) are likely to be ignored.