Skip to content

Monetising APIs

Any HTTPS or WebSocket API can be monetised through Dhali.

There are two main ways to integrate:

  1. Reverse Proxy (easiest)
  2. 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

  1. Go to the API Portal: Open API Portal →
  2. Link your wallet: Authenticate using your preferred wallet.
  3. Create a new API: Navigate to My AssetsCreate.
  4. 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.
  5. 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:

  1. Client Request:
    Users call your API directly and must include a valid Payment-Claim header in every request:

    Payment-Claim: <payment-claim-header>
    
    To allow your users to make payments, see our section on the Dhali payment terminal.

  2. Verification Request:
    Your API extracts that header and makes a call to:

    https://charge.api.dhali.io/<your_api_uuid>
    
    Body:
    { 
      "paymentHeader": "<payment-claim-header>",
      "amount": <optional_integer_amount>
    }
    

  3. The optional amount field specifies how much to charge for the request, measured in the API’s earning currency.
  4. If amount is omitted, Dhali will charge the API’s base earning rate as defined in its metadata.
  5. The amount value must always be an integer, representing the smallest unit of the currency.

    • For example, if the API’s currency has a scale of 6 (like XRP), then:
    • 1 XRP = 1,000,000 drops
    • An amount of 1000000 charges exactly 1 XRP.
  6. 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., XRP or USD).
  • asset_earning_currency.scale — Defines the number of decimal places supported by the currency.
  • For example, XRP uses 6 decimal places, meaning:
    • 1 XRP = 1,000,000 drops
    • A rate of 423 with scale: 6 means 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 as per_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.