Give the table a uniqueness guarantee so duplicates physically can’t happen.
Use an UPSERT (INSERT … ON CONFLICT) with RETURNING so you know whether the row was really inserted.
INSERT … ON CONFLICT
RETURNING
Map that to HTTP status codes.