|
| 1 | +--- |
| 2 | +icon: circle-question |
| 3 | +--- |
| 4 | + |
| 5 | +# Can I get my billing info via API request? |
| 6 | + |
| 7 | +Yes, you can query your account balance and other billing details through the AIML Billing API. |
| 8 | + |
| 9 | +## Get account balance info |
| 10 | + |
| 11 | +<mark style="color:green;">`GET`</mark> `https://billing.aimlapi.com/v1/billing/balance` |
| 12 | + |
| 13 | + |
| 14 | + |
| 15 | +**Headers** |
| 16 | + |
| 17 | +| Name | Value | |
| 18 | +| ------------- | ------------------ | |
| 19 | +| Authorization | `Bearer <token>` | |
| 20 | +| Content-Type | `application/json` | |
| 21 | + |
| 22 | +**Body** |
| 23 | + |
| 24 | +**-** |
| 25 | + |
| 26 | +## Code Example |
| 27 | + |
| 28 | +{% tabs %} |
| 29 | +{% tab title="HTTP" %} |
| 30 | +```http |
| 31 | +GET /v1/billing/balance HTTP/1.1 |
| 32 | +Host: billing.aimlapi.com |
| 33 | +Authorization: Bearer <YOUR_AIMLAPI_KEY> |
| 34 | +Content-Type: application/json |
| 35 | +``` |
| 36 | +{% endtab %} |
| 37 | + |
| 38 | +{% tab title="cURL" %} |
| 39 | +```url |
| 40 | +curl https://billing.aimlapi.com/v1/billing/balance \ |
| 41 | + -H "Authorization: Bearer <YOUR_AIMLAPI_KEY>" \ |
| 42 | + -H "Content-Type: application/json" |
| 43 | +``` |
| 44 | +{% endtab %} |
| 45 | + |
| 46 | +{% tab title="Python" %} |
| 47 | +{% code overflow="wrap" %} |
| 48 | +```python |
| 49 | +import requests |
| 50 | +import json |
| 51 | + |
| 52 | +def main(): |
| 53 | + response = requests.get( |
| 54 | + "https://billing.aimlapi.com/v1/billing/balance", |
| 55 | + headers={ |
| 56 | + # Insert your AIML API Key instead of <YOUR_AIMLAPI_KEY>: |
| 57 | + "Authorization": "Bearer <YOUR_AIMLAPI_KEY>", |
| 58 | + "Content-Type": "application/json", |
| 59 | + }) |
| 60 | + |
| 61 | + data = response.json() |
| 62 | + print(json.dumps(data, indent=2, ensure_ascii=False)) |
| 63 | + |
| 64 | +if __name__ == "__main__": |
| 65 | + main() |
| 66 | +``` |
| 67 | +{% endcode %} |
| 68 | +{% endtab %} |
| 69 | + |
| 70 | +{% tab title="JavaScript" %} |
| 71 | +{% code overflow="wrap" %} |
| 72 | +```javascript |
| 73 | +async function main() { |
| 74 | + const response = await fetch("https://billing.aimlapi.com/v1/billing/balance", { |
| 75 | + headers: { |
| 76 | + "Authorization": "Bearer <YOUR_AIMLAPI_KEY>", |
| 77 | + "Content-Type": "application/json", |
| 78 | + }, |
| 79 | + }); |
| 80 | + |
| 81 | + const data = await response.json(); |
| 82 | + console.log(JSON.stringify(data, null, 2)); |
| 83 | +} |
| 84 | + |
| 85 | +main(); |
| 86 | +``` |
| 87 | +{% endcode %} |
| 88 | +{% endtab %} |
| 89 | +{% endtabs %} |
| 90 | + |
| 91 | +<details> |
| 92 | + |
| 93 | +<summary>Response</summary> |
| 94 | + |
| 95 | +{% code overflow="wrap" %} |
| 96 | +```json5 |
| 97 | +{ |
| 98 | + "balance": 551564495, |
| 99 | + "lowBalance": false, |
| 100 | + "lowBalanceThreshold": 10000, |
| 101 | + "lastUpdated": "2025-11-10T10:01:56.824Z", |
| 102 | + "autoDebitStatus": "disabled", |
| 103 | + "status": "current", |
| 104 | + "statusExplanation": "Balance is current and up to date" |
| 105 | +} |
| 106 | +``` |
| 107 | +{% endcode %} |
| 108 | + |
| 109 | +</details> |
0 commit comments