FastAPI Routing Issue in Hugging Face Spaces

Hello everyone,

I’ve deployed a FastAPI application on Hugging Face Spaces. Everything seems to be running smoothly, and there are no errors in the logs. However, when I try to access my endpoints via a browser or tools like Postman, I’m getting a “404 error” or a “Cannot POST” error.

Here’s a brief overview of my setup:

  • I have a FastAPI route defined as @app.get("/check_request") and another one as"/recommend").
  • My Dockerfile specifies the CMD as CMD ["uvicorn", "app:app", "--host", "", "--port", "7860"].

When I try to access the endpoint in my browser, I get a “404 error”. Similarly, when I use Postman to send a POST request to, I receive a “Cannot POST” error.

Has anyone encountered a similar issue or have any insights on what might be going wrong? Any help or guidance would be greatly appreciated!

Hi @DjPapzin, use this URL as the root:

All spaces are hosted on a separate subdomain and the Hub UI just displays that subdomain in an iframe. I think we block all programmatic requests that aren’t to the subdomain.

Hi @freddyaboulton

Thank you so much for pointing that out! I was indeed trying to access the endpoints through the Hub UI, and your clarification about the separate subdomain makes perfect sense. I’ve now tried using the provided root URL, and it works as expected.

Your assistance has been invaluable, and I genuinely appreciate the time you took to help. It’s gestures like these that make the community such a great place for developers.