from fastapi import FastAPI, HTTPException app = FastAPI() @app.get('/u/{i}') def get(i: int): if i < 0: raise HTTPException(status_code=404, detail='nope') return {'i': i}