Without limits curl can sit on a dead connection for minutes.
curl --connect-timeout 5 --max-time 30 -fsS https://example.com/api
--connect-timeout only limits the connection phase, and --max-time caps the whole transfer including the download. When the limit hits, curl exits with code 28. For large files a total limit is awkward, so use --speed-limit 1000 --speed-time 20, which aborts if the speed stays under 1000 bytes per second for 20 seconds. With --retry the time limit starts again on every attempt, and --retry-max-time caps the total.
Further reading: curl manual