To clarify, I don’t believe that the US is “behind” the coup attempt; I believe they were passively supportive. While the attempt was underway, of course, they will say “we support the democratically elected government”, because that is what they always say, until the government falls, at which point they “support a smooth transition to the restoration of democracy” which means having a military general trade his army uniform for a business suit.
Had the coup attempt succeeded, they would certainly not have intervened, or even demanded, the restoration of the AKP government.
They waited to see which way it would go; waited to see if Fethullahh Gulen really had the influence he claims to have, waited to see if his followers were enough and sufficiently competent to deliver results. They gave PR support to the coup attempt, probably not more than that.
Now, it is back to the drawing board for them, and Gulen may need to look for a job.