unslothai/unsloth · warning · HTTPException

API endpoint not found

Error message

API endpoint not found

What it means

HTTP 404 raised by the SPA catch-all route serve_frontend when the request path starts with api/ or v1/ (or is exactly 'api'/'v1') but matches no registered API route. The handler deliberately raises a real HTTPException so the api_errors handlers render the standard JSON error envelope instead of falling through to index.html.

Source

Thrown at studio/backend/main.py:2354

            headers[_CSP_SCRIPT_NONCE_HEADER] = nonce
        return Response(
            content = content,
            media_type = "text/html",
            headers = headers,
        )

    @app.get("/")
    async def serve_root(request: Request):
        if not _frontend_request_allowed(request):
            return Response(status_code = 404)
        return _build_index_response(request)

    @app.get("/{full_path:path}")
    async def serve_frontend(request: Request, full_path: str):
        # Unknown API paths: raise a real 404 so the api_errors handlers render the right envelope
        # for /v1/* ({"detail": ...} for /api/*). The request path is "/" + full_path.
        if full_path in {"api", "v1"} or full_path.startswith(("api/", "v1/")):
            raise HTTPException(status_code = 404, detail = "API endpoint not found")
        if not _frontend_request_allowed(request):
            return Response(status_code = 404)

        file_path = (build_path / full_path).resolve()

        # Block path traversal — resolved path must stay inside build_path
        if not file_path.is_relative_to(build_path.resolve()):
            return Response(status_code = 403)

        if file_path.is_file():
            return FileResponse(file_path)

        # Serve index.html as bytes — avoids Content-Length mismatch
        return _build_index_response(request)

    return True

View on GitHub (pinned to 203007d190)

Solutions

  1. Check the exact path and method against the backend's OpenAPI schema at /docs or /openapi.json.
  2. Fix typos or version the path correctly (e.g. /api/studio/... vs /v1/...).
  3. If the route should exist, verify the module that registers it is enabled in this build/deployment.
  4. For non-API paths, drop the api/ or v1/ prefix — those are reserved for the API surface.
Defensive patterns

Strategy: type-guard

Try / catch

async def call_api(session, path: str):
    r = await session.get(path)
    if r.status_code == 404:
        detail = r.json().get("detail", "")
        if detail == "API endpoint not found":
            raise UnknownEndpointError(path)  # client bug: path is wrong
    r.raise_for_status()

Prevention

When it happens

Trigger: Requesting an unknown or removed API endpoint such as GET /api/nonexistent or POST /v1/chat/completions when that route is not registered (typo in the path, wrong HTTP method for a differently-named route, or a route that only exists in another deployment).

Common situations: Client/server version skew where the frontend calls an endpoint added in a newer backend; typos in integrations scripts; hitting the REST surface expecting OpenAI-compatible /v1 routes that are disabled in this build.

Related errors


AI-assisted analysis of unslothai/unsloth@203007d190 (2026-08-15). Data as JSON: /api/errors/9dbe5434d827e48b. Report an issue: GitHub.