Overview
Any HTTPS or Websocket API can be monetised through Dhali. There are two ways to integrate with Dhali: through our reverse proxy, or by calling our charging endpoint directly from your API.
Requirements:
- For the Reverse Proxy model (easiest), you will need an HTTPS or Websocket base URL for your API and a header secret so your server can authenticate requests forwarded by Dhali.
- For the Direct Charging model (more control), you only need to know your API's UUID, which is generated when you link your API on Dhali.
- An XRP Ledger or Xahau wallet.
Monetising your API
- Go to the API Portal: Click here
- Link your wallet: Authenticate with your preferred wallet.
- Create a new API: Navigate to "My APIs" and click "Monetise my API".
- Configure your API: A template API will appear on your "My APIs" page. Click it, then click the "Edit" button to configure its details, such as name, base URL, and pricing.
- Choose your Integration Model: After saving, your API page will display the endpoint URL. You have two options for how to use it:
- Reverse Proxy Model (Easiest): Give your users the
https://run.api.dhali.io/<your_api_uuid>
URL. Dhali will act as a reverse proxy, verifying payments before forwarding requests to your API. This requires no changes to your API's code. - Direct Charging Model (More Control): Have users send requests directly to your API. Your service will then need to extract the
Payment-Claim
header and forward it tohttps://charge.api.dhali.io/<your_api_uuid>
for verification. Your API should only fulfill the request after receiving a200 OK
from Dhali.
- Reverse Proxy Model (Easiest): Give your users the
- Inform your users: Share your chosen endpoint with your users. They can learn how to generate payment claims by reading the Using APIs documentation.
For a real-world example of monetizing an API with Dhali, check out our blog post on building a GPT that pays for an XRP API with nano-payments.
Add the payment terminal
You can allow your users to create paid API keys (i.e., payment claims) right from your landing page using the payment terminal: https://pay.dhali.io/
.
This button gives you access to it:
Use the following code in your website to embed this button as a pop-out window:
<button onclick="openDhaliPaymentDialog()">Pay with Dhali</button>
<script>
function openDhaliPaymentDialog() {
var myWindow = window.open("https://pay.dhali.io/", "MsgWindow", "width=500,height=500");
myWindow.focus();
}
</script>
Customizing the Payment Terminal
The payment terminal accepts the following query parameters, allowing you to customize the instructions and behavior for your API. Check out our examples here. This means you can:
- Provide users with clear instructions tailored to your API.
- Control which networks or protocols users can use for payments.
Parameter | Description |
---|---|
uuids Note: Your API's uuid is embedded in its base URL |
(Optional) A comma-separated list of the UUIDs of your APIs (e.g., your XRP API). The payment terminal will display the payment networks for these APIs and provide custom instructions for these APIs. |
Default Behavior | If no uuids parameter is provided, the payment terminal defaults to XRPL.MAINNET and default instructions. |