Monetising APIs
Any HTTPS or WebSocket API can be monetised through Dhali.
There are two main ways to integrate:
- Reverse Proxy (easiest)
- Direct Charging (more control)
Requirements
| Integration Model | What You’ll Need |
|---|---|
| Reverse Proxy | - HTTPS or WebSocket base URL - Header secret for authenticating requests forwarded by Dhali - An XRP Ledger or Xahau wallet |
| Direct Charging | - An XRP Ledger or Xahau wallet |
Monetising your API
- Go to the API Portal: Open API Portal →
- Link your wallet: Authenticate using your preferred wallet.
- Create a new API: Navigate to My Assets → Create.
-
Configure your API:
- A template API will appear on your My Assets page.
- Click it, then select Edit to configure details such as name, base URL, and pricing.
-
Choose your Integration Model:
After saving, your API page will display your endpoint URL.
Select one of the following:
Dhali acts as a reverse proxy, verifying payments before forwarding requests to your API.
No code changes are required.
Your users should call:
https://run.api.dhali.io/<your_api_uuid>
Each request to this endpoint must include a valid payment-claim, embedded in the HTTP header:
Payment-Claim: <payment-claim-header>
To allow your users to make payments, see our section on the Dhali payment terminal.
Your API directly handles payment verification and can control the amount to be charged per request.
Workflow:
-
Client Request:
Users call your API directly and must include a valid Payment-Claim header in every request:To allow your users to make payments, see our section on the Dhali payment terminal.Payment-Claim: <payment-claim-header> -
Verification Request:
Your API extracts that header and makes a call to:Body:https://charge.api.dhali.io/<your_api_uuid>{ "paymentHeader": "<payment-claim-header>", "amount": <optional_integer_amount> } - The optional
amountfield specifies how much to charge for the request, measured in the API’s earning currency. - If
amountis omitted, Dhali will charge the API’s base earning rate as defined in its metadata. -
The
amountvalue must always be an integer, representing the smallest unit of the currency.- For example, if the API’s currency has a
scaleof6(like XRP), then: 1 XRP=1,000,000 drops- An
amountof1000000charges exactly 1 XRP.
- For example, if the API’s currency has a
-
Response Handling:
Fulfill the user’s request only if Dhali responds with:{ "isValid": true }
API Metadata and Pricing Information
Every Dhali-registered API also has an associated metadata endpoint available at:
https://get.api.dhali.io/<your_api_uuid>
This endpoint returns a JSON object describing your API’s currency, earning rate, and other operational metrics such as average cost and inference time.
Example response:
{
"asset_earning_currency": { "scale": 6, "code": "XRP" },
"asset_earning_max_surcharge": 423102,
"asset_earning_rate": 423,
"asset_earning_type": "per_request",
"average_cost": 345,
"average_inference_time_ms": 101.771214,
"name": "tiny-server-mainnet2"
}
Field Descriptions
asset_earning_currency.code— The currency in which the API earns (e.g.,XRPorUSD).asset_earning_currency.scale— Defines the number of decimal places supported by the currency.- For example,
XRPuses 6 decimal places, meaning:1 XRP=1,000,000 drops- A rate of
423withscale: 6means 0.000423 XRP per request.
asset_earning_rate— The base earning rate, expressed in the smallest unit of the currency (e.g., drops for XRP).asset_earning_type— The pricing model, such asper_request.asset_earning_max_surcharge— The maximum additional fee that may be applied, typically in the same smallest unit.average_cost— Average cost per request, based on recent transaction data.average_inference_time_ms— The mean processing time for your API in milliseconds.name— The registered name of your API on Dhali.
This metadata endpoint allows developers, marketplaces, or dashboards to programmatically discover pricing, currency, and performance information about your API and stay updated when you adjust pricing or configuration in the Dhali portal.
For a real-world example, see our blog post on building a GPT that pays for an XRP API with nano-payments.