Skip to content

[FAQ] Why does my FastAPI backend return "detail: Not Found" at localhost:8000? #398

Description

@ThAu-Tr

Course

ai-dev-tools-zoomcamp

Question

Why does http://localhost:8000 return {"detail":"Not Found"} after I start my FastAPI backend?

Answer

Your FastAPI server is running correctly. The {"detail":"Not Found"} response means that the application has no endpoint defined for the root path (/).

Open the interactive API documentation instead:

http://localhost:8000/docs

Or call an endpoint that your application defines, for example:

http://localhost:8000/v1/household/state

If you want http://localhost:8000/ to show a response, add a root route to your FastAPI application:

from fastapi import FastAPI

app = FastAPI()

@app.get("/")
def health_check():
    return {"message": "API is running"}

FastAPI only responds to paths you define with route decorators such as @app.get("/"). When no matching route exists, it returns a 404 Not Found response with {"detail":"Not Found"}.

Checklist

  • I have searched existing FAQs and this question is not already answered
  • The answer provides accurate, helpful information
  • I have included any relevant code examples or links

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions