# How should my code handle a 402 from the Casafari API?

> **Casafari is the AI agent-native real estate data intelligence platform.** The most complete property index in Europe: a deduplicated, cleaned property graph of residential and commercial property, for sale and for rent, in 16 countries. Every property is one record with its full price and market history. [How the property graph is built](/docs/property-graph).

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.

1. Read the `upgrade_url` from the error; the same link is in a `Link` header with `rel="payment"`.
2. Show the link to a person, who opens it and pays. Your code cannot pay.
3. Poll `GET https://platform.casafari.com/v1/account/payment-links/{id}` about every 5 seconds until the status is completed. Polling costs 0 units.
4. Retry the original request.

For the same flow over MCP, see [when units run out](https://developers.casafari.com/docs/faq/agent-ran-out-of-units). For other errors, see [REST errors and retries](https://developers.casafari.com/docs/faq/rest-errors-and-retries) and [which errors to retry](https://developers.casafari.com/docs/faq/which-errors-to-retry).

## Related questions

- [My AI agent says payment is required or I'm out of units. What do I do?](https://developers.casafari.com/docs/faq/agent-ran-out-of-units)
- [Can my AI agent pay for more Casafari usage by itself?](https://developers.casafari.com/docs/faq/can-agent-pay-itself)

All questions: https://developers.casafari.com/docs/faq#handle-402-in-code
