# API Gradio Spaces error API request failed: 404 {"detail":"Not Found"}

**URL:** <https://discuss.huggingface.co/t/api-gradio-spaces-error-api-request-failed-404-detail-not-found/147053>\
**Category:** Beginners\
**Created:** [March 23, 2025, 2:41pm UTC](https://discuss.huggingface.co/t/api-gradio-spaces-error-api-request-failed-404-detail-not-found/147053 "2025-03-23T14:41:07Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![trinhminhhieu](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/trinhminhhieu/32/43922_2.png) [@trinhminhhieu](https://discuss.huggingface.co/u/trinhminhhieu)\
**Post date:** [March 23, 2025, 2:41pm UTC](https://discuss.huggingface.co/t/api-gradio-spaces-error-api-request-failed-404-detail-not-found/147053/1 "2025-03-23T14:41:07Z")

</div>

Hi everyone, I called the correct api link but it doesn’t work even though I have the token  
here logs

```auto

SvelteKitError: POST method not allowed. No actions exist for this page
    at handle_action_json_request (file:///usr/local/lib/python3.10/site-packages/gradio/templates/node/build/server/index.js:926:30)
    at render_page (file:///usr/local/lib/python3.10/site-packages/gradio/templates/node/build/server/index.js:2577:12)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async resolve2 (file:///usr/local/lib/python3.10/site-packages/gradio/templates/node/build/server/index.js:3705:24)
    at async respond (file:///usr/local/lib/python3.10/site-packages/gradio/templates/node/build/server/index.js:3596:22)
    at async Array.ssr (file:///usr/local/lib/python3.10/site-packages/gradio/templates/node/build/handler.js:1261:3) {
  status: 405,
  text: 'Method Not Allowed'
}

```

client nextjs

```auto
const response = await fetch(
      "https://trinhminhhieu-hiussl.hf.space/api/predict",
      {
        method: "POST",
        headers: {
          Authorization: `Bearer ${process.env.HF_TOKEN}`,
          "Content-Type": "application/json",
          Accept: "application/json",
        },
        body: arrayBuffer,
      }
    );

```

---

<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:** [March 23, 2025, 3:33pm UTC](https://discuss.huggingface.co/t/api-gradio-spaces-error-api-request-failed-404-detail-not-found/147053/2 "2025-03-23T15:33:07Z")

</div>

> status: 405,  
> text: ‘Method Not Allowed’

405 errors are very rare. 404 errors are common, though…

> <https://github.com/gradio-app/gradio/issues/4884>
>
> \### Describe the bug
> 
> Originally reported \[here\](https://huggingface.co/spaces/h…ysts/Shap-E/discussions/18).
> 
> If a Space had a method with \`api\_name=False\`, the following error occurs when calling it with \`Client\`:
> \`\`\`
> TypeError: can only concatenate str (not "bool") to str
> \`\`\`
> 
> I think this error occurs when calling a Space with \`gr.Examples\`.
> 
> \### Have you searched existing issues? 🔎
> 
> \- \[X\] I have searched and found no existing issues
> 
> \### Reproduction
> 
> When I use \`Client\` to call \[this Space\](https://huggingface.co/spaces/hysts-debug/client-bool-api-name-error)
> \`\`\`python
> import gradio as gr
> 
> with gr.Blocks() as demo:
> text = gr.Text()
> out = gr.Text()
> btn = gr.Button()
> text.submit(fn=lambda x: x, inputs=text, outputs=out, api\_name=False)
> btn.click(fn=lambda x: x, inputs=text, outputs=out, api\_name='run')
> demo.queue().launch()
> \`\`\`
> with the following code
> \`\`\`python
> from gradio\_client import Client
> 
> client = Client('hysts-debug/client-bool-api-name-error')
> out = client.predict('aaa', api\_name='/run')
> \`\`\`
> I get the following error.
> \`\`\`
> Traceback (most recent call last):
> File "/tmp/temp/run.py", line 4, in \<module\>
> out = client.predict('aaa', api\_name='/run')
> File "/home/ubuntu/.virtualenvs/py31011/lib/python3.10/site-packages/gradio\_client/client.py", line 285, in predict
> return self.submit(\*args, api\_name=api\_name, fn\_index=fn\_index).result()
> File "/home/ubuntu/.virtualenvs/py31011/lib/python3.10/site-packages/gradio\_client/client.py", line 313, in submit
> inferred\_fn\_index = self.\_infer\_fn\_index(api\_name, fn\_index)
> File "/home/ubuntu/.virtualenvs/py31011/lib/python3.10/site-packages/gradio\_client/client.py", line 555, in \_infer\_fn\_index
> if "/" + config\_api\_name == api\_name:
> TypeError: can only concatenate str (not "bool") to str
> \`\`\`
> 
> If I remove the method with \`api\_name=False\`, the error doesn't occur.
> 
> In the case of the \[Shap-E Space\](https://huggingface.co/spaces/hysts/Shap-E), it doesn't have methods with \`api\_name=False\` explicitly, but as it has \`gr.Examples\`, I guess its method has \`api\_name=False\` implicitly and causing this error.
> 
> If I change the code of the Space to the following, the same error occurs.
> \`\`\`python
> import gradio as gr
> 
> with gr.Blocks() as demo:
> text = gr.Text()
> out = gr.Text()
> btn = gr.Button()
> gr.Examples(examples=\['aaa', 'bbb'\], inputs=text)
> btn.click(fn=lambda x: x, inputs=text, outputs=out, api\_name='run')
> demo.queue().launch()
> \`\`\`
> 
> \### Screenshot
> 
> \_No response\_
> 
> \### Logs
> 
> \_No response\_
> 
> \### System Info
> 
> \`\`\`shell
> gradio==3.36.1
> gradio\_client==0.2.8
> \`\`\`
> 
> 
> \### Severity
> 
> Blocking usage of gradio

> <https://github.com/gradio-app/gradio/issues/4591>
>
> \### Describe the bug
> 
> gr.Interface(fn=generate\_answer, inputs=inputs, outputs=ou…tputs, title=title, description=description, examples=examples).launch(share=True,server\_name="172.16.1.88",server\_port=7877,)
> 
> 
> \### Have you searched existing issues? 🔎
> 
> \- \[X\] I have searched and found no existing issues
> 
> \### Reproduction
> 
> I wanted to request the URL using the API, but it failed
> 
> \### Screenshot
> 
> \_No response\_
> 
> \### Logs
> 
> \_No response\_
> 
> \### System Info
> 
> \`\`\`shell
> Name: gradio
> Version: 3.28.3
> Summary: Python library for easily interacting with trained machine learning models
> Home-page: 
> Author: 
> Author-email: Abubakar Abid \<team@gradio.app\>, Ali Abid \<team@gradio.app\>, Ali Abdalla \<team@gradio.app\>, Dawood Khan \<team@gradio.app\>, Ahsen Khaliq \<team@gradio.app\>, Pete Allen \<team@gradio.app\>, Ömer Faruk Özdemir \<team@gradio.app\>
> License: 
> Location: /home/wangchenpeng/miniconda3/envs/glm/lib/python3.9/site-packages
> Requires: aiofiles, aiohttp, altair, fastapi, ffmpy, gradio-client, httpx, huggingface-hub, jinja2, markdown-it-py, markupsafe, matplotlib, mdit-py-plugins, numpy, orjson, pandas, pillow, pydantic, pydub, pygments, python-multipart, pyyaml, requests, semantic-version, typing-extensions, uvicorn, websockets
> Required-by:
> \`\`\`
> 
> 
> \### Severity
> 
> I can work around it

> [@Gradio JS Client Predict Error on Private Space](https://discuss.huggingface.co/t/gradio-js-client-predict-error-on-private-space/114456):
>
> Gradio JS Client raises error when use Private Space. (Python Client works.) connect and view\_api APIs work without any issue. When call predict API, following error happens. (If make space public, no error.) Any help would be appreciated. Response { status: 404, statusText: 'Not Found', headers: Headers { date: 'Tue, 29 Oct 2024 01:06:13 GMT', 'content-type': 'text/html; charset=utf-8', 'content-length': '3020', connection: 'keep-alive', 'x-request-id': 'Sb9C2M', …

---

<div class="post-metadata">

**Author:** ![trinhminhhieu](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/trinhminhhieu/32/43922_2.png) [@trinhminhhieu](https://discuss.huggingface.co/u/trinhminhhieu)\
**Post date:** [March 23, 2025, 3:53pm UTC](https://discuss.huggingface.co/t/api-gradio-spaces-error-api-request-failed-404-detail-not-found/147053/3 "2025-03-23T15:53:19Z")

</div>

Hello here error 404

```auto

Response {
  [Symbol(realm)]: { settingsObject: {} },
  [Symbol(state)]: {
  aborted: false,
  rangeRequested: false,
  timingAllowPassed: false,
  requestIncludesCredentials: false,
  type: 'default',
  status: 404,
  timingInfo: null,
  cacheState: '',
  statusText: 'Not Found',
  headersList: HeadersList {
  [Symbol(headers map)]: Map(12) {
  'access-control-allow-credentials' => 'true',
  'connection' => 'keep-alive',
  'content-length' => '22',
  'content-type' => 'application/json',
  'date' => 'Sun, 23 Mar 2025 15:46:57 GMT',
  'link' => '<https://huggingface.co/spaces/trinhminhhieu/bgnbl>;rel="canonical"', 
  'server' => 'uvicorn',
  'vary' => 'origin, access-control-request-method, access-control-request-headers', 
  'x-proxied-host' => 'http://10.106.9.151',
  'x-proxied-path' => '/run/predict',
},
  [Symbol(headers map sorted)]: null
},
  urlList: [],
  body: {
  stream: <ref *1> ReadableStream {
  _state: 'readable',
  _reader: undefined,
  _storedError: undefined,
  _disturbed: false,
  _readableStreamController: ReadableStreamDefaultController {
  _controlledReadableStream: [Circular *1],
  _queue: S {
  _cursor: 0,
  _size: 0,
  _front: { _elements: [], _next: undefined },
  _back: { _elements: [], _next: undefined }
},
  _queueTotalSize: 0,
  _started: true,
  _closeRequested: false,
  _pullAgain: false,
  _pulling: false,
  _strategySizeAlgorithm: [Function],
  _strategyHWM: 0,
  _pullAlgorithm: [Function],
  _cancelAlgorithm: [Function]
}
},
  source: null,
  length: null
}
},
  [Symbol(headers)]: Headers {
  [Symbol(headers list)]: HeadersList {
  [Symbol(headers map)]: Map(12) {
  'access-control-allow-credentials' => 'true',
  'connection' => 'keep-alive',
  'content-length' => '22',
  'content-type' => 'application/json',
  'date' => 'Sun, 23 Mar 2025 15:46:57 GMT',
  'link' => '<https://huggingface.co/spaces/trinhminhhieu/bgnbl>;rel="canonical"', 
  'server' => 'uvicorn',
  'vary' => 'origin, access-control-request-method, access-control-request-headers', 
  'x-proxied-host' => 'http://10.106.9.151',
  'x-proxied-path' => '/run/predict',

},
  [Symbol(headers map sorted)]: null
},
  [Symbol(guard)]: 'response',
  [Symbol(realm)]: { settingsObject: {} }
}
}
Error: API request failed: 404 {"detail":"Not Found"}

```

here code nextjs api for cloudflare

```auto
/ /api/upload.js
export const runtime = "edge";

export default async function handler(req) {
  // if (req.method !== "POST") {
  // return new Response(JSON.stringify({ error: "Method Not Allowed" }), {
  // status: 405,
  // headers: { "Content-Type": "application/json" },
  // });
  // }

  try {
    // Get form data
    const formData = await req.formData();
    const imageFile = formData.get("image");

    if (!imageFile) {
      return new Response(JSON.stringify({ error: "No file uploaded" }), {
        status: 400,
        headers: { "Content-Type": "application/json" },
      });
    }

    // Convert the File object to ArrayBuffer
    const arrayBuffer = await imageFile.arrayBuffer();

    // Send to HF Space API
    const response = await fetch(
      "https://trinhminhhieu-bgnbl.hf.space/run/predict",
      {
        method: "POST",
        headers: {
          Authorization: `Bearer ${process.env.HF_TOKEN}`,
          "Content-Type": "application/json",
          Accept: "application/json",
        },
        body: arrayBuffer,
      }
    );

    console.log(response);
    if (!response.ok) {
      const errorText = await response.text();
      throw new Error(`API request failed: ${response.status} ${errorText}`);
    }

    const result = await response.json();
    console.log("result", result);

    if (result.error) {
      throw new Error(result.error);
    }

    return new Response(
      JSON.stringify({
        processedImageUrl:
          result.data && result.data[0] ? result.data[0].url : result.url,
      }),
      {
        status: 200,
        headers: { "Content-Type": "application/json" },
      }
    );
  } catch (error) {
    console.error("Error:", error.message);
    return new Response(
      JSON.stringify({
        error: "Failed to process image",
        details: error.message,
      }),
      {
        status: 500,
        headers: { "Content-Type": "application/json" },
      }
    );
  }
}

```

app.py

```auto
with gr.Blocks() as demo:
    gr.Markdown("Background Removal ")
    gr.Markdown("Upload an image to remove the background.")

    with gr.Row():
        input_image = gr.Image(type="pil", label="Upload Image")
        output_image = gr.Image(type="pil", label="Output Image")

    btn = gr.Button("Remove Background")

    btn.click(remove_bg, inputs=input_image, outputs=output_image, concurrency_limit=None)

# demo.queue()
server = demo.launch(share=True)

```

---

<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:** [March 23, 2025, 4:22pm UTC](https://discuss.huggingface.co/t/api-gradio-spaces-error-api-request-failed-404-detail-not-found/147053/4 "2025-03-23T16:22:06Z")

</div>

Same here…

```py
HF_TOKEN = "hf_my_pro_token"
import base64
import requests
response = requests.get("https://raw.githubusercontent.com/gradio-app/gradio/main/test/test_files/bus.png")
buffer = base64.b64encode(response.content)
headers = {'Authorization': f'Bearer {HF_TOKEN}', 'Content-Type': 'application/json'}
response = requests.post('https://john6666-gradio-server-test.hf.space/api/predict', headers=headers, data=buffer)
print(response.content)
# <Response [404]> # Gradio 5.22.0
# <Response [422]> # Gradio 4.44.0

```

---

<div class="post-metadata">

**Author:** ![trinhminhhieu](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/trinhminhhieu/32/43922_2.png) [@trinhminhhieu](https://discuss.huggingface.co/u/trinhminhhieu)\
**Post date:** [March 23, 2025, 4:32pm UTC](https://discuss.huggingface.co/t/api-gradio-spaces-error-api-request-failed-404-detail-not-found/147053/5 "2025-03-23T16:32:47Z")

</div>

Have you found a solution? Nextjs uses API with @gradio/client it works fine but cloudflare doesn’t support nodejs runtime, vercel the 10 second limit is not enough

---

<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:** [March 23, 2025, 4:34pm UTC](https://discuss.huggingface.co/t/api-gradio-spaces-error-api-request-failed-404-detail-not-found/147053/6 "2025-03-23T16:34:31Z")

</div>

No. Requests for private spaces have often failed in the past. The Gradio client is an exception to this.

---

<div class="post-metadata">

**Author:** ![trinhminhhieu](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/trinhminhhieu/32/43922_2.png) [@trinhminhhieu](https://discuss.huggingface.co/u/trinhminhhieu)\
**Post date:** [March 23, 2025, 4:36pm UTC](https://discuss.huggingface.co/t/api-gradio-spaces-error-api-request-failed-404-detail-not-found/147053/7 "2025-03-23T16:36:23Z")

</div>

I spent 2 days still can’t find the solution :))

---

<div class="post-metadata">

**Author:** ![charliebaby2023](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/charliebaby2023/32/32137_2.png) [@charliebaby2023](https://discuss.huggingface.co/u/charliebaby2023)\
**Post date:** [March 26, 2025, 4:14am UTC](https://discuss.huggingface.co/t/api-gradio-spaces-error-api-request-failed-404-detail-not-found/147053/8 "2025-03-26T04:14:42Z")

</div>

i been trying for over three weeks

but HF keeps telling me they’ve fixed it

so

sure glad im not paying for this foolery

now, likely never ever would even consider it

id rather pay for a bag of ice and throw it onto the asphalt

---

<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:** [March 26, 2025, 6:33am UTC](https://discuss.huggingface.co/t/api-gradio-spaces-error-api-request-failed-404-detail-not-found/147053/9 "2025-03-26T06:33:36Z")

</div>

The output isn’t perfect, but it does respond, so maybe it’s fixed.

```py
HF_TOKEN = "hf_my_pro_token"
import base64
import requests
response = requests.get("https://raw.githubusercontent.com/gradio-app/gradio/main/test/test_files/bus.png")
buffer = base64.b64encode(response.content)
headers = {'Authorization': f'Bearer {HF_TOKEN}', 'Content-Type': 'application/json'}
response = requests.post('https://john6666-gradio-server-test.hf.space/api/predict', headers=headers, data=buffer)
print(response.content)
# :[{"type":"json_invalid","loc":["body",0],"msg":"JSON decode error","input":{},"ctx":{"error":"Expecting value"}}]}'

```

---

<div class="post-metadata">

**Author:** ![Yosun](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/yosun/32/46148_2.png) [@Yosun](https://discuss.huggingface.co/u/Yosun)\
**Post date:** [April 23, 2025, 7:30am UTC](https://discuss.huggingface.co/t/api-gradio-spaces-error-api-request-failed-404-detail-not-found/147053/10 "2025-04-23T07:30:37Z")

</div>

bash curl has the same issue
