Paying and running out of units · FAQ
How should my code handle a 402 from the Casafari API?
Treat a 402 payment_required from the self-serve platform as a pause: pass the upgrade_url to a person, poll the payment link until it completes, then retry the request.
Errors are application/problem+json, and each error type has a page at https://platform.casafari.com/errors/<code>, such as https://platform.casafari.com/errors/payment_required.
- Read the
upgrade_urlfrom the error; the same link is in aLinkheader withrel="payment". - Show the link to a person, who opens it and pays. Your code cannot pay.
- Poll
GET https://platform.casafari.com/v1/account/payment-links/{id}about every 5 seconds until the status is completed. Polling costs 0 units. - Retry the original request.
For the same flow over MCP, see when units run out. For other errors, see REST errors and retries and which errors to retry.