api:ai:quota-autotopup
Table of Contents
API : AI quota : Automatic AI top-up
Introduction
This request sets the automatic AI top-up of a customer (portal: customer details, under AI product): an AI top-up product that the API buys by itself every time one of the customer's AI resources (transcription, summary, text to speech) reaches 80 % of what is available for the month - so the allowance never runs out. Send null to stop buying automatically.
How it works:
- The trigger is the same moment the 80 % / 100 % usage warning is decided after each counted AI request (see AIUsageCounters
notified). It is claimed atomically, and only on current numbers. A single request that jumps straight past 100 % triggers it too. - One API server buys at a time per customer (Redis lock
aiAutoTopUp:lock:<customer id>, 60 s expiry), and every purchase is decided on the usage and limit as they are right then - so overlapping requests never buy more than the usage needs. Nothing is bought into the next month for a crossing at the end of a month. - The top-up is bought exactly like Buy top-up does it - credit first, a locked invoice line, a reseller invoice line, re-armed warnings, the change log and the recording catch-up. The invoice line description starts with
AI top-up (automatisk), and the change log entryAI top-up bought automaticallynames the employee who set the automatic top-up up, impersonated by the system. - It is bought again and again until the resource is below 80 % of the raised limit - at most 10 times per crossing, which only a top-up far too small for the usage ever reaches (logged as a warning). It is bought again at every later crossing in the month; there is no monthly cap.
- The usage-limit subscribers (employees with
notifyOnGeneralUsageLimiton the customer,notifyOnGeneralUsageLimitReselleron the reseller) get the e-mailai_auto_topup.html/ai_auto_topup_reseller.html- what was bought, how many times, the price of one and the usage after it - instead of the 80 % / 100 % warning, which the raised limit has made untrue. - When the purchase fails - the product has ended, been deleted or no longer fits the customer's AI product, or the customer is not active - the failure is logged to syslog (
ai-auto-topup: … failed) and the ordinary 80 % / 100 % warning is sent as before. Quota status reports such a top-up withavailable: false. - When the customer moves to another reseller the automatic top-up is removed - it names a product from the old reseller's range.
The product must be one the user could buy for the customer right now: it must be among the Top-up products for this user and customer (so a customer OWNER cannot choose a reseller-only product, a RESELLER can). The setting is stored as finance.aiAutoTopUp on Customers and is never taken from a customer update.
Request
| URL | https://api.telecomx.dk/ai/quota/autotopup | |
|---|---|---|
| Method | PUT | |
| Access level | OWNER for the user's own customer, with write access to it. RESELLER, RESELLER_ADMIN or ADMIN, who may also name another customer with customer. |
|
| Query | customer | [optional] Id of the customer to set it for. Only honoured for RESELLER and up, and write access to the customer is checked. Defaults to the user's own customer. |
| JSON body | ||
|---|---|---|
| product | Id | [required] Id of the AI_TOP_UP product to buy automatically, or null to stop buying automatically. |
Body examples
{ "product": "650000000000000000000420" } { "product": null }
Response
| JSON object | ||
|---|---|---|
| success | Boolean | True on success. |
| autoTopUp | Object | The automatic top-up as Quota status reports it, null when it was removed. |
Example
{ "success": true, "autoTopUp": { "_id": "650000000000000000000420", "name": "AI top-up: 5 hours transcription", "price": 199.00, "aiTopUp": { "sttSeconds": 18000, "llmTokens": 0, "ttsCharacters": 0 }, "from": "2026-10-25T12:00:00.000Z", "available": true } }
Errors
| Error code | Message | Description |
|---|---|---|
| 422 | product | Product id is invalid |
| 404 | product | No product in the body, or the product is not a top-up this user may buy for the customer |
| 422 | customer | Customer id is invalid |
| 404 | customer | Customer not found |
| 403 | access_denied | Insufficient access level, or no write access to the customer |
| 500 | internal_error | <Unspecified> |
api/ai/quota-autotopup.txt · Last modified: by Telecom X AI
