# API call URL error

**URL:** <https://discuss.huggingface.co/t/api-call-url-error/158971>\
**Category:** Beginners\
**Created:** [June 11, 2025, 9:45pm UTC](https://discuss.huggingface.co/t/api-call-url-error/158971 "2025-06-11T21:45:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![puathepig79](https://avatars.discourse-cdn.com/v4/letter/p/9e8a1a/32.png) [@puathepig79](https://discuss.huggingface.co/u/puathepig79)\
**Post date:** [June 11, 2025, 9:45pm UTC](https://discuss.huggingface.co/t/api-call-url-error/158971/1 "2025-06-11T21:45:09Z")

</div>

Hello! I am currently in the process of setting up the api calls and routing for one of my projects, but am running into an error.  
When i run the following code:

> **Code**
>
> app.post(‘/api/calculate’, authenticateToken, async (req, res) =\> {  
> try {
> 
> ```
> const hfResponse = await fetch('https://api-inference.huggingface.co/models/gpt2', {
> method: 'POST',
> headers: {
> Authorization: `Bearer ${process.env.HUGGINGFACE_API_KEY}`,
> 'Content-Type': 'application/json'
> },
> body: JSON.stringify("Hello World!")
> });
> 
> if (!hfResponse.ok) {
> const errorText = await hfResponse.text();
> console.error(`HF API error: ${hfResponse.status} ${errorText}`);
> return res.status(hfResponse.status).json({ error: errorText });
> }
> 
> const result = await hfResponse.json();
> const text = Array.isArray(result) ? result[0]?.generated_text : result.generated_text;
> 
> res.json({ recommendations: text });
> 
> ```
> 
> } catch (err) {  
> console.error(‘Fetch failed:’, err);  
> res.status(500).json({ error: ‘Failed to get AI response’ });  
> }  
> });

It gives me the following error:  
HF API error: 404 Not Found

I have checked and my API token seems to be working and gpt2 should be available to my free account. The API token exists in a seperate .env file that is in the same folder as the code was run in.

Is it an error with my URL? I’ve tried some other variations but everything has returned the same result. Please help me troubleshoot. Thank you so much!

---

<div class="post-metadata">

**Author:** ![John6666](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/john6666/32/27664_2.png) [@John6666](https://discuss.huggingface.co/u/John6666)\
**Post date:** [June 12, 2025, 2:15am UTC](https://discuss.huggingface.co/t/api-call-url-error/158971/2 "2025-06-12T02:15:30Z")

</div>

There are two problems. One is that the URL for the request is probably wrong. The other is that it may not have been deployed, so I don’t know if it can be used…

I think it can be used with the deployed model…

```js
// https://api-inference.huggingface.co/models/gpt2
https://router.huggingface.co/hf-inference/models/openai-community/gpt2/v1/chat/completions

```

> **[openai-community/gpt2 · Hugging Face](https://huggingface.co/openai-community/gpt2)**
>
> We’re on a journey to advance and democratize artificial intelligence through open source and open science.

One of deployed models:

> **[Qwen/QwQ-32B · Hugging Face](https://huggingface.co/Qwen/QwQ-32B)**
>
> We’re on a journey to advance and democratize artificial intelligence through open source and open science.
