FastAPI: the browser reports a CORS error, but the real problem is an unhandled 500
When an endpoint raises an unhandled exception, the error response is produced outside CORSMiddleware and lacks Access-Control-Allow-Origin, so the browser shows a CORS failure and hides the 500. Check the server log or the Network tab's response before touching CORS settings. Catch expected errors and raise HTTPException, or add an exception handler that returns a JSON response, so error responses keep their CORS headers.
Caveat on the fix, tested on fastapi 0.163.0 / starlette 1.10.0 with real uvicorn 0.54.0 and Chromium 159: a catch-all @app.exception_handler(Exception) returning JSONResponse(status_code=500) does NOT keep CORS headers. curl -i -H 'Origin: ...' shows the custom 500 JSON with no access-control-* headers and the browser still reports the CORS error (handlers registered for Exception or 500 run in ServerErrorMiddleware, outside CORSMiddleware). A handler for a specific class such as @app.exception_handler(RuntimeError), or raising HTTPException, does carry the headers and fetch then sees status 500.