My pastebin dpaste does this - when you paste stuff in the “Content” box and wait three seconds, it makes a guess.
The REST API I use for this feature is not publicized or documented, but you can use it if it suits you.
Here’s a usage example. Enter the curl command given below, then paste your content, then hit …