This looks like a service that does what you're asking for, if I'm understanding your ask and this page correctly: https://developers.coinbase.com/docs/wallet/guides/send-receive
This would require you to already have USD on deposit in your Coinbase account. The page says they are working on a feature to automatically withdraw USD from a linked bank account (I wouldn't hold my breath for this).
Since you explicitly asked about doing this via an API, I looked into this aspect a little bit, too:
In the example json on the right, I'm seeing that it has separate "amount" and "native amount" sections specifying BTC and USD respectively, and there's an "instant_exchange" field. This leads me to believe it can do exactly what you're asking for, provided you have USD on deposit and instantly available:
- Hold USD, not BTC
- Create a new transaction to send BTC, via API
- USD is converted to BTC "just-in-time" at time of transaction
I didn't look into converting a USD amount to BTC based on the current price via Coinbase's API, but of course their API will provide for that (via a previous request).
blockchain.info also offers a free API to do this, although I'm sure the precise exchange rate on Coinbase will vary slightly from what blockchain.info reports: https://blockchain.info/tobtc?currency=USD&value=500
Hope that helps.. although I imagine you've probably answered this yourself since posting this question.