The --max-filesize option specifies the maximum file size:
$ curl URL --max-filesize bytes
The curl command will return a non-zero exit code if the file size exceeds the limit or a zero if the download succeeds.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month, and much more.